IE8中的过滤器不起作用,在IE8中修复rgba

时间:2016-03-15 09:40:38

标签: html css filter internet-explorer-8 rgba

我需要在IE8中使用rgba(alpha)做背景色,但我的代码不起作用 HTML:

<div class="container">
    <div class="child">
    </div>
</div>

CSS:

.container {
    position: fixed; 
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000,endColorstr=#99000000);
}
.child {
    width: 50px;
    height: 50px;
    color: red;
}

1 个答案:

答案 0 :(得分:0)

由于IE8确实支持rgb()作为背景色,因此结果是一个纯色框。

因此我们需要在rgb规则之后将背景设置为透明(仅在IE8及以下版本中)。在谷歌搜索后,答案是backslash 9 hack

#div{
    background:rgb(255,0,0);
    background: transparent\9;
    background:rgba(255,0,0,0.3);
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#4cFF0000,endColorstr=#4cFF0000);
    zoom: 1;
}
#div:nth-child(n) {
    filter: none;
}

有关详情,请按照教程http://rland.me.uk/cross-browser-alpha-transparent-background-10-2011

进行操作