I'm attempting to create an image overlay effect where one image is placed on top of another, similar to the screenshot provided. Check out the screenshot here
However, I'm facing an issue where the overlaying image remains stationary when the screen size changes. I want it to maintain its position relative to the background image no matter what. I've tried adjusting the positions and widths of both images and their container, but haven't been successful in achieving the desired result.
.img-container {
position: relative;
width: 800px;
/* Set to the size of your background image */
height: auto;
}
.background-img {
width: 100%;
height: 100%;
position: relative;
z-index: 1;
/* Background image stays behind */
}
.overlay-img {
position: absolute;
top: 10rem;
/* Adjust the position of the overlay image */
left: 45rem;
max-width: 100%;
/* Set size of the overlay image */
z-index: 2;
/* Overlay image appears on top */
}
<section id="portfolio">
<div class="img-container">
<img class="background-img" src="https://picsum.photos/1000/1000">
<img class="overlay-img" src="https://picsum.photos/200/300" alt="">
</div>
</section>