gpt4 book ai didi

html - 无法控制div内图像的不透明度

转载 作者:太空狗 更新时间:2023-10-29 14:56:11 26 4
gpt4 key购买 nike

我希望 div 中的图像是不透明的,而 div 是透明的。我尝试设置图像和 div 的不透明度,但它不起作用。

jsFiddle 链接:http://jsfiddle.net/2BNEF/10/

我希望图像是不透明的,文本是透明的。

<div id="targetframe">
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes
<div id="target">
out. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their defaul
<img class="myimage" src="http://www4.picturepush.com/photo/a/1365552/480/trucks-photgraphy/asdf-%2858%29.jpg?v0"/>
</div>
</div>


#targetframe {
background: none repeat scroll 0 0 black;
border: 2px inset grey;
font-family: Verdana,sans-serif;
left: 0;
margin: 0;
overflow: hidden;
padding: 0;
position: absolute;
top: 0;
opacity: 0.5;
}
#target {
background: none repeat scroll 0 0 transparent;
height: 100%;
left: 0;
position: relative;
top: 0;
width: 100%;
z-index: 0;
}
.myimage {
opacity: 1;
}

最佳答案

如果你在一个元素上设置了opacity,那么它会被那个元素的所有后代( child ,所有 child 的 child ......)继承,你无能为力以防止这种情况

在这种情况下,您可以只为 div 使用 RGBa 背景(rgba(0,0,0,.5) 而不是黑色 - DEMO )。 RGBa 具有出色的支持 - 唯一不支持它的浏览器是 IE8 及更早版本,对于这些浏览器,您可以使用 filter 渐变。

关于html - 无法控制div内图像的不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12269454/

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