我想要一个包含一些文本的 div。 在那个 div 中,我还想要一个匹配相同位置和比例的 div。 我在 stackoverflow 上发现了很多东西,但只要发现不同,它就对我不起作用。
现在,我看不到文字了。为什么? 如果解决方案不影响“#container”的 css,那就太好了。
html:
<div id="container">
<p>Somt text to screw with me</p>
<div class="background-img"></div>
</div>
CSS:
#container {
position: fixed;
left: 10px;
top: 30px;
width: 100px;
height: 50px;
background: red;
}
p {
color: blue;
}
.background-img {
position: absolute;
background-size: cover;
background-repeat: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: url(http://lorempixel.com/420/255);
}
对于 fiddle 手: https://jsfiddle.net/clankill3r/8kaLj2su/
最佳答案
将 z-index: -1
添加到您的背景图片。
关于html - 无法正确获取包装器 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29257556/