If you want to position an image behind a container using CSS, you can utilize the z-index
property. By setting the image's z-index to -1 and the container's z-index to 1, you can achieve the effect of a background image. Make sure to position the image absolutely and fill the entire parent element with it.
Here is an example implementation:
**Sample code in index.html
**
<div class="container">
<div class="content">
<img src="./images/img.jpg" alt="">
<h1>My content</h1>
</div>
</div>
**Sample code in style.css
**
.container {
position: relative;
display: grid;
place-content: center;
z-index: 1;
}
.container .content {
width: 100%;
height: 100%;
background-color: #00000052;
}
.container img {
position: absolute;
z-index: -1;
width: 100%;
height: 100%;
object-fit: cover;
}