首先看看A级浏览器所支持的用CSS实现元素透明的方案:
| 浏览器 | 最低 版本 | 方案 |
|---|---|---|
| Internet Explorer | 4.0 | filter: alpha(opacity=xx); |
| 5.5 | filter: progid:DXImageTransform.Microsoft.Alpha(opacity=xx); | |
| 8.0 | filter: "alpha(opacity=xx)"; | |
| Firefox (Gecko) | 0.9 (1.7) | opacity |
| Opera | 9.0 | opacity |
| Safari (WebKit) | 1.2 (125) | opacity |
实际上在IE8中,-ms-filter是filter的别名,两者区别是-ms- filter的属相值必须被单引号或双引号包围,而filter中则不是必须,而在IE8之前的版本中,filter的属性值必须不被单引号或双引号包围。
IE中的HTML元素要实现透明,则其必须具备layout,这样的元素有仅可读的属性hasLayout,且其值为true。具体情况如下:
body、img、table、tr、th、td等元素的hasLayout一直为true。 type为text、button、file或select的input的hasLayout一直为true。 {position:absolute}的元素的hasLayout为true {float:left|right}的元素的hasLayout为true {display:inline-block}的元素的hasLayout为true {height:xx}或{width:xx}的元素必须具体以下两个条件之一,其hasLayout才能为true: display的值是block,如demo3就不行。 {zoom:xx}的元素在IE8的兼容模式或IE8之前的浏览器中其hasLayout为true,但在IE8的标准模式下则不会触发hasLayout。 {writing-mode:tb-rl}的元素的hasLayout为true。 contentEditable的属性值为true。 {display:block}的元素的hasLayout一直为true,如demo8。 关于hasLayout的更多详情可以看Exploring Internet Explorer “HasLayout” Overview和On having layout
从上面就可以看出IE实现HTML元素的透明如此混乱,为了向下兼容和自己的私有属性让IE上实现元素透明有多种方式,比如CSS Opacity实例中的demo1到demo8,虽然IE 团队推荐实现透明的方式是:
新闻热点
疑难解答