如何使用CSS使仅背景DIV透明
我正在使用CSS attrubutes:
filter: alpha(opacity=90);
不透明度:.9;
使DIV透明,但是当我在该DIV中添加另一个DIV时,它也使其透明。
我想使外部(背景)DIV仅透明。怎么样 ?
回答:
内部DIV无法撤消外部DIV的不透明度属性。如果要实现透明度,请使用rgba
或hsla
:
外层div:
background-color: rgba(255, 255, 255, 0.9); /* Color white with alpha 0.9*/
内部div:
background-color: #FFF; /* Background white, to override the background propery*/
因为您已经添加filter:alpha(opacity=90)
了问题,所以我假设您还想要IE(旧版本)的有效解决方案。这应该可以工作(-ms-
IE的最新版本的前缀):
/*Padded for readability, you can write the following at one line:*/filter: progid:DXImageTransform.Microsoft.Gradient(
GradientType=1,
startColorStr="#E6FFFFFF",
endColorStr="#E6FFFFFF");
/*Similarly: */
filter: progid:DXImageTransform.Microsoft.Gradient(
GradientType=1,
startColorStr="#E6FFFFFF",
endColorStr="#E6FFFFFF");
我使用了Gradient滤镜,以start-
和开头end-
color,因此背景不会显示渐变,而是显示出平坦的颜色。颜色格式为ARGB十六进制格式。我编写了一个JavaScript代码段,将相对不透明度值转换为绝对的alpha-
hex值:
var opacity = .9;var A_ofARGB = Math.round(opacity * 255).toString(16);
if(A_ofARGB.length == 1) A_ofARGB = "0"+a_ofARGB;
else if(!A_ofARGB.length) A_ofARGB = "00";
alert(A_ofARGB);
以上是 如何使用CSS使仅背景DIV透明 的全部内容, 来源链接: utcz.com/qa/404143.html