The card-img-overlay in Bootstrap 5 seamlessly integrates into the following div container

Currently, I am in the process of creating a painting website layout for my CS50 homepage. However, there seems to be an issue with the background-color: rgba(0,0,0,0.7); not aligning correctly with the images within the card-group.

<div class="card-group">
  <div class="card bg-dark text-white">
      <img src="pics/painterpic.jpg" class="card-img-top" alt="Exterior Cover"/>
  </div>
 <div class="card">
      <img src="pics/cover.jpg" class="card-img-top" alt="Interior Cover"/>
 </div>
      <div class="card-img-overlay">
          <h1 class="card-title" id="hero-text">Interior Painting Specialists</h1>
      </div>
</div>

CSS:
card-img-overlay {   background-color: rgba(0,0,0,0.7) }
card-img-top   { width: 100%; height: 100%;}

I have experimented with using <div class="container-fluid> or just container and tried various modifications like:

.card-img-overlay { background-color: rgba(0,0,0,0.7) position: absolute; top: 0; right: 0; bottom: 0; left: 0; padding: 1.25rem; border-radius: calc(.25rem - 1px); }

And many other variations while adding width: 100%; height;}

The frustrating part is that the img-overlay extends beyond the div it belongs to, protruding about 3 or 4 inches further out. This has left me scratching my head at why this is happening despite trying different solutions.

If anyone has any insights or suggestions on how to resolve this issue, your input would be greatly appreciated. Thanks!

Here's all the CSS code that I've utilized:

.box300 {
width:100%;
margin:0 auto 0 auto;
padding:5px;
border:1px solid #999;
background:#fff;
}

#hero-text {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 56px;
}

#p-1 {
text-align: center;
position: absolute;
top: 62.5%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 18px;
}

.card-img-top {
width: 100%;
height: 100%;
}

.card-img-overlay {
background-color: rgba(0,0,0,0.5);
overflow: hidden;
}       

Answer №1

After our conversation, I have put together a sample that aligns with your requirements:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.card-group {
  display: grid;
  grid-template-columns: 50% 50%;
  grid-gap: .5rem;
  height: 400px;
  position: relative;
}

.card-group__image {
  height: 400px;
  width: 100%;
  object-fit: cover;
}

.card-group__title {
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  transform: translateY(-50%);
  padding: 3rem;
  background-color: rgb(0 0 0 / 65%);
  color: white;
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
<div class="card-group">
  <img class="card-group__image" src="https://images.pexels.com/photos/807598/pexels-photo-807598.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" class="card-img-top" alt="Exterior Cover" />
  <img class="card-group__image" src="https://images.pexels.com/photos/793012/pexels-photo-793012.jpeg?auto=compress&cs=tinysrgb&w=1600" class="card-img-top" alt="Interior Cover" />
  <h1 class="card-group__title" id="hero-text">Interior Painting Specialists</h1>
</div>

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

Why is my CSS and Bootstrap full-page image not displaying properly?

I've been struggling to get a full-page image to display on my website and resize responsively across different screens. I've searched through w3schools and Stack Overflow for solutions, but no matter what I try, it just doesn't seem to work ...

What is the best way to animate the preprending of a div in an AJAX response?

Here is the code I am currently working with: $.ajax({ type: 'POST', url: 'load_more.php', data: {val:myval}, success: function (data) { $("#load_current").prepend(data); ...

Can someone please explain the purpose of row-sm and row-cols-sm-n (where n<12)? I've come across the col-sm-n (where n<12) but I'm unsure about how row-sm is used

From my understanding, when using col-sm-n in Bootstrap, the columns in a row will stack on top of each other when the device screen width is less than the specified size for sm. But what about row-sm? Does it function similarly to col-sm? And what exactly ...

Animation using jQuery is functional on most browsers, however, it seems to

After creating an animation to simulate an opening door using jQuery, I discovered that it works perfectly on Firefox 24, Chrome 28, and IE 8. However, Safari presents a problem - the door opens but then the "closed" door reappears at the end of the animat ...

Transforming the NavBar in React: A guide to dynamically updating values

I am facing an issue with my NavBar that changes based on certain events. The current setup works fine, but I don't want to render it in every class that loads a new page. Initially, I had the NavBar rendering inside App.js so it could appear on all p ...

Is there a way to transmit a div using Node.js?

Scenario: I am developing a web application that allows users to draw on a canvas, save the drawing as an image, and share it with others using Node.js. Current Progress: Drawing functionality (real-time updates on both clients). Saving the canvas as a ...

The Android WebView is unable to run JavaScript code in a local HTML file

Currently, I am attempting to load a local HTML file from the assets folder into a webview. Even though I can successfully load the HTML file in the webview, there seems to be an issue with the file's reliance on an external .js file for calculations. ...

Modify the input value when using the get_search_form() function in Wordpress

After experimenting with the latest get_search_form() function in WordPress, I've encountered an issue where I can't figure out how to remove the text label from the search submit button. Does anyone have any suggestions or solutions for this pr ...

Guidelines for determining a screen's location using Javascript

I have integrated a label onto an image and I am trying to figure out how to determine the exact position of each label on the screen. Is there a way to retrieve the screen coordinates for each label? Below is the code snippet that I have uploaded, perha ...

"Combining JSON, JavaScript, and HTML for dynamic web development

I am a junior computer programmer facing challenges with our JSON project. The objective is to store an object in local storage, but my HTML and JS code are not working as intended. It seems like nothing happens at all. Any suggestions or feedback would ...

Is there a way to clear a @font-face downloaded font from the browser cache?

Recently, I realized that I made an error in my webapp release by using a limited version of "Droid Sans" with @font-face for Latin characters. The font files are hosted on my server. To rectify this issue, I have now updated the font to the full version s ...

Tips for making a hide and reveal FAQ section

Currently working on creating a FAQ page for my website, I ran into a challenge. My goal is to have a setup where clicking on a question will reveal the answer while hiding any previously open answers. So far, I have managed to achieve this functionality p ...

Looking for an Icon to accompany the navigation bar on Bootstrap

Can anyone assist me with adding an icon next to the navbar starting from the word "Dashboard" without any spacing using only Bootstrap? Please note that I have tried options like offset-5 and ms-5 but they did not achieve the desired result. <div id=& ...

Chrome DevTools automatically translates all HEX color codes into their corresponding RGB values

Chrome DevTools now automatically converts all HEX colors to RGB values, even if the color is set in CSS or using DevTools. Is there a way to prevent this conversion? I know about the method of holding down Shift + clicking the color icon to convert color ...

Encountered a glitch during the npm installation process for mui core

I recently set up a new create-react-app and am still encountering the same error message. After installing MUI, I'm getting an 'unable to resolve dependency tree' issue. npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve depende ...

Can parameters be included in the HTML class attribute?

Is it possible to embed specific information into HTML elements, like images, without disrupting valid HTML markup? Would the following example be considered valid HTML? <img src="..." class="isearcher:tags(paris+hilton,gary+suneese)" > The idea is ...

Fading away backdrop images for the header

I've created a header class in my CSS with the following styling- header { background-image: url('../img/header-bg.jpg'); background-repeat: none; background-attachment: scroll; background-position: center center; .backg ...

Remove newline character from HTML code using Python 3.2 and urllib module

After fetching HTML content as a string using urllib, I encountered difficulty in searching the string due to its HTML format. Is there any way to "unformat" the string by removing all the new lines without altering the HTML code itself? Here is the Pytho ...

Is it possible to use Primefaces tooltip to show at the bottom of the page

When I hover over the PrimeFaces tooltip, it displays at the bottom of the page. Here is my code and image link: <!DOCTYPE html> <h:html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com ...

How can I incorporate a vertical line divider and a legend into a curved box using HTML and CSS?

https://i.sstatic.net/dj4zb.png I have this image that I need to divide into three sections with a legend at the top, similar to the image shown. So far, this is the code I have, but I'm struggling with creating the vertical line, adding space betwe ...