IE6是支持!important的
2012-05-24 16:26
423 查看
备注:写在同一选择器中的!important是不被IE6所认的,而分开情况的则正常
参考:http://blog.dmtuan.com/?p=183
<!DOCTYPE html><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IE6支持important</title>
<style type="text/css">
.box { background:red;}
.box { background:green !important; }
.box-box { background:green !important; background:red;}
</style>
</head>
<body>
<div class="box">IE6支持important</div><!--所有浏览器都是green-->
<div class="box-box">IE6支持importantt</div><!--IE6浏览器是红色--->
</body>
</html>
IE6是支持!important的
转自:http://bbs.blueidea.com/thread-2982362-1-1.html
首先,这个题目有点老了。为什么要写这个,是因为我在一个群里讨论CSS规则优先级的时候,说了句!important级别最高。因果被批判的体无完肤,什么“!important不好用,谁没事会用它”,“IE6根本不支持这个东西”之类的话。我想说IE6真的是支持!important的。网上很多讲CSS HACK的教程都有这样的内容,如果想写一个让FF、IE7、IE8可以识别,并且IE6不能识别的CSS HACK,就用!important。造成的结果就是很多人以为!important在IE6下根本不支持,本人当时就是受害者之一。!important在CSS1中就有描述,链接如下:http://www.w3.org/TR/CSS1/#important。为什么会造成IE6不支持的假象呢,原因是IE6有BUG。在IE6中,下面的这段代码显示是不正确的。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<style type="text/css">
div {
width: 100px;
height: 100px;
background: red !important;
background: yellow;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
提示:您可以先修改部分代码再运行
在标准浏览器下,这个DIV应该是红色的,但在IE6下是黄色的。这个只能说是IE6的BUG,而不能说IE6完全不支持!important。如果把上面的代码改为:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<style type="text/css">
div {
width: 100px;
height: 100px;
background: red !important;
}
div {
background: yellow;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
提示:您可以先修改部分代码再运行
怎么样,可以正常显示了吧。同理,下面的代码在IE6下也可以正确显示的。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<style type="text/css">
div {
width: 100px;
height: 100px;
background: red !important;
}
#div1 {
background: yellow;
}
</style>
</head>
<body>
<div id="div1"></div>
</body>
</html>
提示:您可以先修改部分代码再运行
结论:作为CSS优先级别的老大,!important是全浏览器兼容的。
相关文章推荐
- IE6对!important单个的类是支持的
- 辩驳一个默认的说法:IE6不支持!important
- IE6支持!important吗?
- ie6并不是不支持!important
- IE6 IE7(Q) IE8(Q) 不完全支持 !important 规则
- [转]IE6对!important支持不彻底
- 辩驳一个默认的说法:IE6不支持!important (转http://www.cnblogs.com/lanyueer/archive/2011/03/29/1998398.html)
- IE6支持!important吗 如何用!important解决浏览器兼容性问题
- 关于Internet Explorer 6(IE6)不支持CSS中!important属性
- IE6支持important的小注意
- ie6下面不支持!important的处理方法
- IE6不完全支持!important
- 我需要支持IE6么?
- 让IE6、IE7、IE8支持CSS3的圆角、阴影样式
- JS代码判断浏览器版本,支持IE6,IE7,IE8,IE9!
- 圆角: ie6-8不支持的问题
- 提示不支持IE6的脚本
- IE6不支持position:fixed的解决方法
- ajaxFileUpload.js 无刷新上传图片,支持多个参数同时上传,支持 ie6-ie10