发新话题
打印

div+css使用!important标记区别Firefox和IE6

div+css使用!important标记区别Firefox和IE6

[使用!important标记可以区别Firefox和IE6]
Firefox支持!important标记,而IE6忽略!important标记,因此可以使用!important标记区别Firefox和IE6。

<html>
<body>
<div style="color: black !important; color: white;">
firefox中显示为黑色文字,IE6中显示为白色文字
</div>
<div style="color: white !important; color: black;">
firefox中显示为白色文字,IE6中显示为黑色文字
</div>
</body>
</html>

[使用!important区分Firefox和IE6时需要放在前面]
<html>
<body>
<div style="color: red !important; color: blue;">
使用!important区别firefox与IE6时,要注意实现原理,Firefox识别!important标记,相当于提升了带有! important的权重,当样式设置为color: red !important; color: blue;时,Firefox认为color: red !important;的权重大于color: blue;,所以Firefox识别为color: red;。而IE6不识别!important标记,当样式设置为color: red !important; color: blue;时,IE6认为color: red !important;的权重和color: blue;的权重相同,由于color: blue;的位置靠后,所以IE6识别为color: blue;。
</div>
<div style="color: red; color: blue !important;">
如果!important设置在靠后。当样式设置为color: red; color: blue !important;时,Firefox认为color: blue !important的权重大于color: red;,所以Firefox识别为color: blue;。而IE6不认别!important标记,当样式设置为color: red; color: blue !important;时,IE6认为color: red;的权重和color: blue !important;的权重相同,由于color: blue !important;的位置靠后,所以IE6也识别为color: blue;。此时,!important就没有起到区分Firefox与IE6的作用。
</div>
</body>
</html>

TOP

纯支持

提示: 作者被禁止或删除 内容自动屏蔽

TOP

发新话题