Jeekundo.com

以前端技术为主

谁说IE6不支持!important

with 2 comments

许多人认为ie6不支持!important,其实是被一条针对ie 6的css hack给误导了。

这条css hack是:

.test {
    height: auto !important;
    height: 500px;
}

.test的高度在其他浏览器里面是auto,而在ie6里面是500px,许多人在解释这条css hack之所以会生效是因为ie6不支持!important,误导了不少人。

其实ie6本身是支持!important的,下面换一种写法:

.test {
    height: auto !important;
}
.test {
    height: 500px;
}

发现ie6里面.test的高度也是auto,这说明ie6是支持!important的。那上面的hack之所以会生效是因为ie6的一个小小的bug,即当你把两条相同的声明放到同一个选择器里面的时候ie6才不认识!important。然而大部分时候,这个小小的bug并不影响我们在ie6内使用!important。

Related Posts

  • No Related Post

Written by admin

December 12th, 2009 at 11:27 pm

Posted in 前端技术

2 Responses to '谁说IE6不支持!important'

Subscribe to comments with RSS or TrackBack to '谁说IE6不支持!important'.

  1. IE6的呈现真是让人弄不明白。。。

    George Wing

    27 Feb 10 at 1:05 pm

  2. I’m impressed! It’s too bad more folks haven’t heard about this place, it covered what I needed to know!

Leave a Reply