利用IE6对!important的解释差异做Hack

简介:
< !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 > 
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf-8"  /> 
< title >important </title> 
< style  type ="text/css" > 


color:red !important;/*现代浏览器*/ 
color:blue;/*ie6为蓝色*/ 

</style> 
</head> 

< body > 
   < p >段落文本 < p > 
</body> 
</html>
 
在这里color属性先后重复定义,注意!important的位置。
 
在IE6中结果
段落文本
 
FF3:
段落文本
 
看来IE6是认为后面定义的覆盖前面的喽,标准浏览器会正确对待!important,优先级最高。
 
这并不代表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 > 
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf-8"  /> 
< title >important </title> 
< style  type ="text/css" > 


color:red !important;/*现代浏览器&&IE6*/ 



color:blue; 

</style> 
</head> 

< body > 
   < p >段落文本 < p > 
</body> 
</html>
 
这时候ie6中也是红色了,认识的IE6的这个差异在我们平时中能免去了不少麻烦。



本文转自 xcf007 51CTO博客,原文链接: http://blog.51cto.com/xcf007/102824 ,如需转载请自行联系原作者
相关文章
|
4月前
|
Web App开发 前端开发
CSS Hack是什么?ie6,7,8的hack分别是什么
CSS Hack是什么?ie6,7,8的hack分别是什么
131 0
|
Web App开发 前端开发
区分IE6,IE7,IE8,IE9,FireFox,Chrome浏览器的CSS hack
区分IE6,IE7,IE8,IE9,FireFox,Chrome浏览器的CSS hack
|
Web App开发 前端开发 JavaScript
|
Web App开发 前端开发 容器
CSS- ie6,ie7,ie8 兼容性写法,CSS hack写法
css ie6,ie7,ie8 兼容性写法,CSS hack写法   margin-bottom:40px;       /*ff的属性*/margin-bottom:140px\9;    /* IE6/7/8的属性 */color:red\0;              /* IE8支持 */*...
1021 0
|
前端开发 Go Windows
|
Web App开发 前端开发 iOS开发
CSS IE6/7/8, Firefox, Safari, Chrome, Opera Hack使用简要归纳(转)
网上有很多关于IE6/7/8, Firefox, Safari, Chrome, Opera CSS Hack的文章,但我觉得太过繁杂,要不给出一张看也看不懂的CSS Hack归纳表,要不就是给出一大堆代码说明问题,不便于学习与使用。
1323 0
|
Web App开发
IE8 HACK介绍
1.‘\9’:     eg:.test { color/*\**/: blue\9 }.header {width:300px;} /* 所有浏览器*/.header {width/*\**/:330px\9;} /* 所有浏览器IE浏览器 */.
900 0