I have customized the CSS code below to style a div
element that showcases a responsive image.
.my-img-container {
position: relative;
&:before {
display: block;
content: " ";
background: url("https://lorempixel.com/300/160/") no-repeat;
background-size: 100% 100%;
width: 100% !important;
padding-top: 56.25%;
}
>img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100% !important;
height: 100% !important;
}
}
<div class="my-img-container">
<img srcset="https://lorempixel.com/540/304 540w, https://lorempixel.com/960/540 960w" sizes="(min-width: 576px) 540px, 100vw" src="https://lorempixel.com/300/160">
</div>
I am attempting to show an image in the background while the responsive image loads using the content
in the CSS, but it's not functioning as expected. Any thoughts on why this may be happening?