Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to get an image to overlay the parent div

Featured Replies

Hello,

I would like to create the below using a div container and then have the image coming out of it.

I use bootstrap, so any assistance and help is appreciated.

image.png.0d337174bad58b5de059f3733901bc9a.png

 

Thanks

Set a white background to the parent div then a grey background to the child div then layer the image over the top

Or...

Add the white and grey backgrounds to the image.

Or...

Don't bother as it's not going to work properly on a small screen anyway.

Any why on earth are you still using bootstrap! It's bloated, dated and poorly responsive.

  • 2 months later...

It's been a long time (16 years lol)

Just having a play with this. I am using grid for overlays. Reasonably new to me, but if you set two elements to the same 'area' they will overlap. 

This is vanilla CSS not bootstrap. You may be able to extract something from it, I don't know.

codepen link here

It is responsive, but would benefit from having a non-cropped cat :)

edit: having issue formatting a link here `[link](url)` doesn't work. Can you not use basic markdown here?

https://codepen.io/rpg2019/pen/YPzmpWR

Have also noticed that the OP posted back in January, so may well be long gone. Only just noticed sorry.

Edited by RLM
Adjust comment

  • 5 months later...

To make an image overlay its parent <div>, you can use absolute positioning combined with position: relative on the parent. This way, the image will be positioned relative to the parent container and can stretch across it.

Here’s an example:

<div class="parent">
  <img src="example.jpg" alt="Overlay Image" class="overlay-img">
  <p>Some content inside parent div</p>
</div>

.parent {
  position: relative; /* Makes this the reference for absolutely positioned children */
  width: 300px;
  height: 200px;
  background: #f0f0f0;
}

.overlay-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;   /* Cover full width */
  height: 100%;  /* Cover full height */
  object-fit: cover; /* Maintain aspect ratio */
  opacity: 0.7;  /* Optional: make it semi-transparent */
  z-index: 1;    /* Ensure it's above the background but you can adjust for content */
}

This makes the image cover the parent div like a background. If you need text or other elements to appear above the image, give them a higher z-index.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.