Bootstrap Overlapping Problem: Find a Solution

Currently, I am in the process of learning how to create a responsive website using bootstrap. Although I have been making progress, I realize that my code may not be as clean as it could be. However, my current concern revolves around overlaying an image on my site.

No matter what I try, I cannot seem to make the overlay match the size of the image rather than the size of the containing <div>.

To simplify things, I have reduced my problem down to the basic elements.

The main issue I am facing is with the padding: the background (shown in blue at the bottom of the image below) matches the size of the <div> and <row>, but not the size of the actual image. The image itself has inherent padding of 25px on top, 15px on the right, and another 15px on the left.

Despite trying to apply padding to the <div>, the background still does not match the dimensions of the image. It seems that the padding within the image is related to the functioning of bootstrap...

Here is a visual representation from the Firefox console displaying the padding and div size:

View Image

The current code snippet:

View Code

I would greatly appreciate any assistance in resolving this issue. I believe there must be a solution, but my current skill level is hindering me, even after several hours of effort!

Thank you in advance for your help! :)

Answer №1

Your parent class called .overlay:

The

wrapper reve col-xl-4 col-lg-6 col-md-12 col-sm-12
class has a padding: 15px.

Therefore, setting width: 100% will take that into account.

I recommend using width: calc(100% - 30px); (to offset the 15px padding on each side)

EDIT: The 15px padding is applied by Bootstrap's .col-* classes. You can find this information in the "Computed" tab in your browser's source code.
On Line 628:

.col-1, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-10, .col-11, .col-12, .col,
.col-auto, .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12, .col-sm,
.col-sm-auto, .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12, .col-md,
.col-md-auto, .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12, .col-lg,
.col-lg-auto, .col-xl-1, .col-xl-2, .col-xl-3, .col-xl-4, .col-xl-5, .col-xl-6, .col-xl-7, .col-xl-8, .col-xl-9, .col-xl-10, .col-xl-11, .col-xl-12, .col-xl,
.col-xl-auto {
  position: relative;
  width: 100%;
  padding-right: 15px;
  padding-left: 15px;
}

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

Using the download attribute with anchor tags in React components

I utilize cloud storage to store my files, and during the upload process, they receive unique prefixes in their names. For instance, if I upload a file called test.txt, it will be saved as 7ea205f01ae5_test.txt. It's worth mentioning that I also captu ...

How come applying a unique class to a bootstrap element is unsuccessful in Chrome but operates seamlessly in Edge?

I have customized some elements created using Bootstrap 4 by adding a unique class called ukzcol to change the background color. It works perfectly fine in the navigation section. Here is the ukzcol class: .ukzcol { background-color: rgb(0, 23, 51) !imp ...

Modifying a CSS property with jQuery

If I have the following HTML, how can I dynamically adjust the width of all "thinger" divs? ... <div class="thinger">...</div> <div class="thinger">...</div> <div class="thinger">...</div> ... One way to do this is usi ...

The functionality of Google Maps code is limited on Android devices because the map feature is not available

After updating the Google Maps embed code to be responsive for mobile devices, I discovered that the map still won't display on Android or iPhone. The following is the modified code. Can anyone assist me in resolving this issue so that the map can sho ...

How come flex won't let me rearrange an image?

.nav { height: 500px; } .navphoto { height: 500px; display: flex; justify-content: flex-end; } <div class="nav"> <img class="navphoto" src="images/navphoto.jpg"> </div> Just wondering why I can't seem to move an image, bu ...

Is it possible to manually trigger a version change transaction in IndexedDB?

I have been working on a Chrome extension that uses the IndexedDB to store data client-side in an IDBObjectStore within an IDBDatabase. The data structure requires users to be able to modify the object store freely, such as adding new objects or modifying ...

Locating the value of a data attribute from a distant parent div using jQuery

How can I access the closest div from an anchor tag that has a data-id attribute without using multiple parent() methods? Even though .parent().parent().parent() works, I am trying to find a better solution. <div class="panel panel-default" data-id="@ ...

Position the mat-icon button in the top right corner for the close button

I'm struggling with positioning my close icon button at the top right corner of my dialog box. Here is my app-iconbutton component: <button mat-icon-button class="iconbutton" [ngStyle]="{ 'background-color': back ...

iPhone 5s landscape mode causing issues with media query

I have been testing a media query that looks like this: @media screen and (max-width: 600px) { .blah { font-size: 1.25rem; } } When I test this in responsive mode on browser dev tools, everything looks great. I can see all the changes as I resize ...

Trigger an event in jQuery when the focus moves away from a set of controls

Within a div, I have three textboxes and am looking for a way to trigger an event when focus leaves one of these inputs without transitioning to another one of the three. If the user is editing any of the three controls, the event should not be triggered. ...

Web Scraping for Results on Android

Hello, I am embarking on a new endeavor in Android Studio where I am attempting to build an application that can submit a form on a website's HTML and then parse the resulting HTML page for data. While I have some experience with Jsoup in the past, my ...

Change the visibility of a div's content when a radio button is selected with only CSS

When the radio buttons are on the same div level as "content1" and "content2", it works properly. But how can I make it work if I move the radio buttons to another div outside of the "second" div? For example, if toggle1 is checked then content1 should be ...

Horizontal Screen Sharing on iPad

Currently, I have a two-column website set up using Wordpress. However, I am facing an issue with the right side column scrolling over on iPads. While the page behaves properly on desktops, on iOS devices, the div is able to scroll over the navigation ba ...

Unable to get click function to work with multiple div elements

Using four div elements, I have implemented a feature where clicking on the first div causes all other div elements to change opacity. This is working correctly. However, I would like the opacity of the first div to remain unchanged when moving to another ...

Display the application unless a certain condition is met, in which case trigger an alert notification

Goal: My objective is to trigger an Alert component if a specific condition is met (e.g., no data from URL pathname), otherwise, render the application as usual. Approach I've Taken app.layout = dbc.Container([ dbc.Alert([...], id='alert&ap ...

jquery mobile integrated seamlessly between image1 and image2

One issue I'm facing with jquery.mobile is that there seems to be a gap between photo1 and photo2 when displayed on my mobile device. Any suggestions on how to eliminate this space and have the images appear seamlessly next to each other? Thank you in ...

Is it possible to use a shell script to replace the external CSS file link in an HTML file with the actual content of the CSS file

Seeking a solution for replacing external CSS and JS file links in an HTML document with the actual content of these files. The current structure of the HTML file is as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C ...

What could be the reason for jQuery not functioning properly as needed?

function toggleDisplayingRooms(nameSelect){ if(nameSelect){ firstroom = document.getElementById("firstroom").value; secondroom = document.getElementById("secondroom").value; thirdroom = ...

How to align radio buttons in the center of a div horizontally

I am struggling to center a group of three radio buttons horizontally and have not been successful. Below is the code I am using: HTML <div class="section-wrap section-flavors"> <input id="r11" name="radio3" type="radio" value="radio_bt ...

Customize your click event with conditional styling in React

When the onClick event is triggered, I am attempting to modify a class by calling my function. It appears that the function is successfully executed, however, the class does not update in the render output. Below is the code snippet: import React from &ap ...