我正在尝试将文本放置在图像上(这里简化为一个div),我可以对其进行模糊处理和设置其他过滤器,但我希望该文本是相对定位的,以便父容器可以调整大小。
#container {
position: relative;
width: 100%;
background: red;
height: 300px; /* For display sample purposes--no height is defined in production */
}
.bg {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: blue;
opacity: 0.5;
}
.content {
color: white;
font-weight: bold;
font-size: 3em;
}
<div id="container">
<div class="bg"></div>
<div class="content">
asdasdasdasd
</div>
</div>
这会导致蓝色的 bg
显示在 content
上方。我知道可以将 content div 也绝对定位,但那样容器的高度不会改变。
我该如何实现我想要的效果呢?
bg
显然在文本上方,使其呈蓝色。如果你提高bg
的不透明度,文本将完全不可见。 - idlackage