IE8 下的 RGBA 兼容问题

问题表述:

1
2
background:rgba(0,0,0,.5); /*支持rgba的浏览器*/
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#7f000000,endColorstr=#7f000000); /*IE8支持*/

下图为 rgba 和 IE filter 的转换

代码:

hack写法:
[不直接在样式里面添加filter,而是判断是否为ie添加filter]
[IE9同时支持RGBA和filter]

1
2
3
4
5
6
7
8
9
<!--[if lt IE 9]>
<style type="text/css">
.color-block {
background:transparent;
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#7f000000,endColorstr=#7f000000);
zoom: 1;
}
</style>
<![endif]-->