【发布时间】:2020-07-11 03:32:07
【问题描述】:
我目前将以下 CSS 代码应用于显示响应式图像的 div 元素。
.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>
我想要做的是在加载响应图像时在背景中显示图像,因此 CSS 中的 content,但它不起作用。知道为什么吗?
【问题讨论】:
标签: html css pseudo-class responsive-images