CSS Hack 是我们解决浏览器兼容性 (尤其是 IE 各版本) 问题的常用手段. CSS Hack 的手法可以说是五花八门, 使用时经常混淆. 下面是一个汇总, 以便查阅. js 代码 /* Selector Hacks **/
- / IE6 及更低版本浏览器 /
- html #uno { color: red }
- / IE7 /*:first-child+html #dos { color: red }
- / IE7, FF, Saf, Opera /
- html>body #tres { color: red }
- / IE8, FF, Saf, Opera (除了 IE 6,7 的所有浏览器) /
- html>/**/body #cuatro { color: red }
- / Opera 9.27 and below, safari 2 /
- html:first-child #cinco { color: red }
- / Safari 2-3 /
- html[xmlns*=""] body:last-child #seis { color: red }
- / safari 3+, chrome 1+, opera9+, ff 3.5+ /
- body:nth-of-type(1) #siete { color: red }
- / safari 3+, chrome 1+, opera9+, ff 3.5+ /
- body:first-of-type #ocho { color: red }
- / saf3+, chrome1+ /
- @media screen and (-webkit-min-device-pixel-ratio:0) {
- diez { color: red }
- }
- / iPhone / mobile webkit /
- @media screen and (max-device-width: 480px) {
- veintiseis { color: red }
- }
- / Safari 2 - 3.1 /
- html[xmlns*=""]:root #trece { color: red }
- / Safari 2 - 3.1, Opera 9.25 /
- |html[xmlns=""] #catorce { color: red }
- / 除了 ie 6-8 的所有浏览器 /
- :root *> #quince { color: red }
- / IE7 /*+html #dieciocho { color: red }
- / Firefox. 1+ /
- veinticuatro, x:-moz-any-link { color: red }
- / Firefox 3.0+ /
- veinticinco, x:-moz-any-link, x:default { color: red }
- / FF 3.5+ /
- body:not(:-moz-handler-blocked) #cuarenta { color: red; }
- /* Attribute Hacks **/
- / IE6 /
- once { _color: blue }
- / IE6, IE7 /
doce { color: blue; /* 或者 #color: blue */ }
- / 所有浏览器, 除了 IE6 /
- diecisiete { color/**/: blue }
- / IE6, IE7, IE8 /
- diecinueve { color: blue\9; }
- / IE7, IE8 /
- veinte { color/*/: blue\9; }
- / IE6, IE7 -- 和! important 作用相同 /
- veintesiete { color: blue !ie; } / 感叹号后边可以是任意字符串 /
- / IE8, IE9 /
anotherone {color: blue\0/;} /* 必须放在所有规则的最后面 /[/code]
来源: http://www.qdfuns.com/article/11377/3a7c3ed2a75bd549f32e25a58aeeb263.html