gpt4 book ai didi

css - 对图像应用不透明度会导致绝对 div 也透明

转载 作者:行者123 更新时间:2023-11-28 17:54:02 25 4
gpt4 key购买 nike

我有以下结构的图片库:

<div class="gallery">
<div class="message">
Welcome to gallery
</div>
<img src="http://placehold.it/300x300" />
</div>

还有 CSS:

.message {
position:absolute;
left:10px;
top:20px;
height:30px;
width:140px;
background:#333;
}
.gallery img {
opacity:.85;
}

但这会导致 div message 也是透明的!如何防止它以及透明的原因是什么?

DEMO

最佳答案

图像似乎位于消息 div 的顶部。我只是像这样交换了它们:

<img src="http://placehold.it/300x300" />
<div class="message">
Welcome to image gallery
</div>

这为我解决了问题。

fiddle

另一种方法是像这样给消息一个 z-index:

.message {
position:absolute;
left:150px;
top:20px;
height:30px;
width:140px;
background:#333;
z-index: 2;
}

.gallery img {
opacity:.85;
}

fiddle

关于css - 对图像应用不透明度会导致绝对 div 也透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21643562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com