兼容IE6 IE7 Firefox的CSS hack方法

支付宝内搜索 9155838 即可领现金红包 每天都能领哦

以前我写CSS代码大部分都是用!important来hack。
在ie6和firefox环境中测试可以正常显示,并成功的应用了hack技术。
但是发布了ie7后,它对!important可以正确解释,页面没有能够按要求显示!

我找到一个针对IE7不错的hack方式:使用“*+html”!
现在用IE7浏览一下,应该没有问题了。

示例如下: #example { color: #333; } /* Mozilla FireFox*/ * html #example { color: #666; } /* IE6 */ *+html #example { color: #999; } /* IE7 */

那么在firefox下字体颜色显示为#333,
IE6下字体颜色显示为#666,
IE7下字体颜色显示为#999,并且它们互不干扰!

区别IE6与FF:background:orange;*background:blue;

区别IE6与IE7:background:green !important;background:blue;

区别IE7与FF:background:orange; *background:green;

区别FF,IE7,IE6:background:orange;*background:green !important;*background:blue;

注:IE都能识别*;符合web标准的浏览器(如firefox)不能识别*

总结
IE6能识别*,但不能识别 !important,
IE7能识别*,也能识别!important;
FF不能识别*,但能识别!important;

另外再补充一个,下划线"_",
IE6支持下划线,IE7和firefox均不支持下划线。

于是大家还可以这样来区分IE6,IE7,firefox
: background:orange;*background:green;_background:blue;

注:不管是什么方法,书写的顺序都是firefox的写在前面,IE7的写在中间,IE6的写在最后面

推荐文章

仅有 1 条评论
  1. qqq

    不错 。。学习了 。。。

    qqq 回复
发表新评论