标题:解决IE6、IE7、Firefox兼容最简单的CSS Hack 出处:Husw!OnRoad 在路上 时间:Fri, 30 Dec 2011 00:37:40 +0000 作者:我就是个世界 地址:https://www.husw.net/blog/IE6_IE7_Firefox_CSS_Hack/ 内容: ------------------------------------------ 2012年5月30日 更新 -------------------------------------------------------------- 区别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都能识别*;标准浏览器(如FF)不能识别*; IE6能识别*,但不能识别 !important, IE7能识别*,也能识别!important; FF不能识别*,但能识别!important; 另外再补充一个,下划线"_", IE6支持下划线,IE7和firefox均不支持下划线。 于是大家还可以这样来区分IE6,IE7,firefox: background:orange;*background:green;_background:blue; "/9" 例:"margin:0px auto/9;".这里的"/9"可以区别所有IE和FireFox. "*" IE6、IE7可以识别.IE8、FireFox不能. "_" IE6可以识别"_",IE7、IE8、FireFox不能. 如此,就可以完全区分开IE6、IE7、IE8、FireFox了. --------------------------------------------------------------------------------------------------- background: red; /* 对FF Opera和Safari有效 */ #background: blue; /* 对 IE6 和 IE7有效 */ _background: green; /* 只对IE6有效 */ /*/background: orange;*/ /** 只对IE8有效 **/ !important /*FF、IE7有效*/ * /*IE都有效*/ ============================================================ IE8是可以和IE7兼容的,简单一行代码,让IE8自动调用IE7的渲染模式 只需要在页面中加入如下HTTP meta-tag: 只要IE8读到这个标签,它就会自动启动IE7兼容模式,保证页面完整展示。 注:不管是什么方法,书写的顺序都是firefox的写在前面,IE7的写在中间,IE6的写在最后面。 -------------------------------------------------------------------------------------------------------- 具体写法很容易: #someNode { position: fixed; #position: fixed; _position: fixed; } 第一排给Firefox以及其他浏览器看 第二排给IE7(可能以后的IE8、IE9也是如此,谁知道呢)看 第三排给IE6以及更老的版本看 最好的应用就是可以让IE6也“支持”position:fixed,而且,配合这个原理,可以做到不引入JavaScript代码(仅用IE6的expression),我这里有一个现成的页面,CSS如下写: #ff-r { position: fixed; _position: absolute; right: 15px; top: 15px; top: expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop+15 : document.body.scrollTop + (document.body.clientHeight -this.clientHeight)); } 是不是很方便:) 来源:aw's blog http://www.awflasher.com/blog/archives/1080 Generated by Bo-blog 2.1.2 beta 3