您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何使用CSS使仅背景DIV透明

如何使用CSS使仅背景DIV透明

内部DIV无法撤消外部DIV的不透明度属性。如果要实现透明度,请使用rgbahsla

外层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 2022/1/1 18:14:58 有529人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶