【发布时间】:2015-04-26 22:52:49
【问题描述】:
如何在 HTML <img> 之上重复这个 1px x 1px CSS 背景图像?
http://jsfiddle.net/hjv74tdw/1/
我遇到了CSS show div background image on top of other contained elements,但它似乎需要一个额外的 div。理想情况下,我希望我根本不必使用 div,但根据CSS Background-image over HTML img,这实际上是不可能的,至少对于 100% 宽度响应的场景来说是不可能的。
.test {
background: url(http://placehold.it/1/1) repeat;
position: relative;
z-index: 100;
width: 200px;
}
.test img {
width: 100%;
display: block;
position: absolute;
z-index: 50;
}
<div class="test">
<img src="http://lorempixel.com/400/400">
</div>
【问题讨论】: