The placement and dimensions of a transparent black filter in CSS using bootstrap 4

I am currently working with the latest version of bootstrap and I am facing some challenges with the CSS due to my lack of familiarity with it (I have very little experience with bootstrap).

My goal is to add a black filter to my images (specifically those on the right in the "Qui suis-je" section), similar to what I have successfully done with my slider. However, there seems to be a shift in the layout, possibly due to the col classes. I want to maintain the same padding, so setting "padding: 0" for the parent element (class sec-1-2) makes it too large.

Could someone provide assistance with this issue?

You can view my website (which is still under construction) here: blog.amelie-mathieu.fr, and see a screenshot of the problem. You can also inspect the code using browser console, but I have included the relevant code snippet below.

Thank you for your help!

.sect-1-2 {
    height: 100%;
}

.sect-1-2 img {
     position: relative;
     z-index: 1;
 }

.play img {
    width: 80px;
    position: absolute;
    z-index: 5;
    display: inline-block;
    margin-top: 15%;
}

.play {
    text-align: center;
}
<div class="sect-1-2 col-lg-6 col-md-12">
         <div class="transparent-bg2"></div>
         <div class="play"><img src="images/play.png"/></div>
         <div><img src="images/Thumbnail-CV-vidéo-Janvier-2018.png" class="img-fluid"/></div>
    </div>

Answer №1

An issue arises with the absolute positioning of .transparent-bg2, as it removes it from the document flow, resulting in the padding of the parent element being ignored. To address this issue, one potential solution is to utilize the calc() function to set the width of the absolutely positioned element to 100% - 30px (the total width of the padding on the parent element):

.transparent-bg2 {
    background-color:rgba(0, 0, 0, 0.4);
    position:absolute;
    visibility:visible;
    opacity:1;
    transition:opacity 0.5s linear;
    width:calc(100% - 30px); /* deduct parent element padding from width */
    height:100%;
    z-index:2;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Choosing Issues

My selectpicker is displaying data outside the dropdown menu before making a selection. The data appears both inside and outside of the dropdown. Can someone please help me identify the issue and guide me on how to fix it? <select class="selectpick ...

Efficiently reducing the size of a CSS selector string with javascript

Is there a library that already performs this function? I've only been able to find online tools. The reason I am interested in accomplishing this task using JavaScript is because I need to ensure that the strings a > b, a and a> b,a are conside ...

Adjust the alignment of the final row in several div elements within a container

I am working with a container div that houses several nested divs. Here is the CSS code for the structure: .result-container { max-width: 650px; margin: 0 auto; background: blue; border: 1px solid; position: relative; text-align: center; } . ...

Syncing user information with MySQL database

I have created a user profile page that pulls in the information of the logged-in users. The issue I am facing is that when I click on the submit button, all the updated information gets sent to an edit_profile.php file except for the password field. I hav ...

What is the proper way to add a date and time into a MYSQL database using an HTML form

Dealing with the transition from "datetime" to "datetime-local" in HTML5 has unexpectedly caused some complications for me. Due to this shift, inserting datetime values into a MySQL table using an HTML form has become problematic, especially when using Car ...

Advantages and disadvantages of fetching image paths repeatedly from the database compared to retrieving them from session storage

Currently, I am displaying profile images using session like the following code snippet: <img src="<?php if (isset($_SESSION['userimage'])){ echo $_SESSION['userimage']; }?>" /> What are the advantages and disadvantages of ...

Adjust the position of an element based on changes in window size using jQuery

Wondering if this question is unique, as I've spent quite some time searching for a solution to this issue without any luck. Perhaps my search criteria aren't correct. I have a navigation bar that becomes fixed when it reaches the top of the vie ...

Here is a unique version: "Guidelines for changing the default text " - " inside a button class='btn'> " - "< once the element is hovered over:after"

When hovering, the output always displays as "1IPSUM". However, adding a ':before' element with 'content:"1"' results in the output before hover being "11" The desired output is: while hovering, display "IPSUM" Fiddle Link: https://j ...

Using media queries in VueJS style tags may not have the desired effect

I've encountered an issue with using @media in the style tags of a VueJS component. Surprisingly, styling within the @media query works consistently, while applying styles based on width rules does not seem to have any effect. <template> &l ...

Minimizing the use of line breaks in HTML to enhance visual design characteristics

While working with Bootstrap and HTML to construct a website, I have frequently resorted to using line breaks in the code for design purposes. However, I believe there must be a more professional approach to achieve the desired layout. For instance, on ...

Tips for translating an HTML webpage from Arabic to English

I have a bootstrap site with HTML pages but no backend functionality. How can I manually translate from Arabic to English, given that I already have the translations for all content and don't need to rely on translation tools? Is there a way to map Ar ...

Obtaining the referring URL after being redirected from one webpage to another

I have multiple pages redirecting to dev.php using a PHP header. I am curious about the source of the redirection. <?php header(Location: dev.php); ?> I attempted to use <?php print "You entered using a link on ".$_SERVER["HTTP_REFERER"]; ?> ...

Enhanced functionality for Thingworx using ThreeJS

I'm currently facing an issue while developing a 3 JS extension for Thingworx, specifically with the renderHtml function when working with a 3 JS canvas (Check out the code). //runtime.ts file renderHtml(): string { let htmlString = '<div ...

Navigate to the line situated at the exact midpoint vertically

I have a div with child elements, each containing a line of text. <div id="aboutxt"> <div class="line">TEXT_LINE_ONE</div> <div class="line">TEXT_LINE_TWO</div> <div class="line">TEXT_LINE_THREE</div> ...

Adding to the beginning of a list in JQuery mobile

Having trouble figuring out how to prepend my list in jQuery mobile while keeping the divider on top of the most recent item added. I attempted to prepend the newly added item, but it ended up shifting the divider to the bottom instead. function loadScan ...

What is the best way to attach a function to an href attribute for creating a dynamic link?

I've been struggling to pass a function to the href attribute in my link tag, but no matter what I try, it just doesn't seem to work. It either redirects to a 404 page or is completely unclickable. What could be causing this issue? This link app ...

Is it possible to trigger a reflow prior to initiating a lengthy JavaScript operation?

Ready to face the criticism, I understand that this question has been asked many times before, and I am aware that there are likely more efficient ways to achieve what I'm trying to do... In a JavaScript function, I have a process that can take up to ...

Loop through each div using jQuery and dynamically add or remove a class to

I am looking to create an infinite loop that adds a class to each div with a timeout in between. Currently, I have implemented it like this: $(document).ready(function() { $('.small-bordered-box').each(function(i) { var $t = $(this); ...

Why isn't the card positioned in the center of the screen?

Why is the card not centered on the screen as it is supposed to be? I am utilizing Bootstrap 4.5 <div class="container"> <div class="row"> <div class"col"></div> <div class="col-8"> <div class="card"> ...

Unable to stop the default form submission in Vue 3

Using the latest version of Vue 3 I am encountering an issue with preventing form submission. Here is my HTML form: <form id="app" @submit="onSubmit"> <input type="text"> <input type="text"> ...