建議:以標準瀏覽器爲準書寫代碼,如遇到兼容問題,嘗試其餘方法解決問題,在萬不得已怕狀況下,採用HACK解決。html
如下是我總結的HACK書寫方法:web
瀏覽器:僅限IE6+,FF,safari,chrome,opera;(截止到2011.10.12非IE均爲最新版本)。chrome
測試環境:windows系統;windows
DOCTYPE:.瀏覽器
標誌符 | 示例 | IE6 | IE7 | IE8 | IE9 | FF | OP | SA | CH |
---|---|---|---|---|---|---|---|---|---|
* | .eq {*color:#000;} | Y | Y | N | N | N | N | N | N |
_ | .eq {_color:#000;} | Y | N | N | N | N | N | N | N |
+ | .eq {+color:#000;} | Y | Y | N | N | N | N | N | N |
- | .eq {-color:#000;} | Y | N | N | N | N | N | N | N |
> | .eq {>color:#000;} | Y | Y | N | N | N | N | N | N |
\0 | .eq {color:#000\0;} | N | N | Y | Y | N | Y | N | N |
\9 | .eq {color:#000\9;} | Y | Y | Y | Y | N | N | N | N |
\9\0 | .eq {color:#000\0;} | N | N | N\Y | Y | N | N | N | N |
:root .xx{xxx:xxx\9;} | :root .eq {color:#a00\9;} | N | N | N | Y | N | N | N | N |
*+ | .eq {*+color:#000;} | Y | Y | N | N | N | N | N | N |
*- | .eq {*-color:#000;} | Y | N | N | N | N | N | N | N |
*html | *html .eq {color:#000;} | Y | N | N | N | N | N | N | N |
*+html | *+html .eq {color:#000;} | N | Y | N | N | N | N | N | N |
html* | html* .eq {color:#000;} | Y | Y | N | N | N | N | N | N |
[; | .eq {color:red;[;color:blue;} | Y | Y | N | N | N | N | Y | Y |
html>body | html>body .eq {color:blue;} | N | Y | Y | Y | Y | Y | Y | Y |
html>/**/body | html>/**/body .eq {color:blue;} | N | N | Y | Y | Y | Y | Y | Y |
html/**/>body | html/**/>body .eq {color:blue;} | N | Y | Y | Y | Y | Y | Y | Y |
@media all and (min-width:0px){} | @media all and (min-width:0px){.eq {color:#000;}} | N | N | N | Y | Y | Y | Y | Y |
*:first-child+html | *:first-child+html .eq {color:blue;} | N | Y | N | N | N | N | N | N |
*:first-child+html{} *html | *:first-child+html{} *html .eq {color:blue;} | Y | N | N | N | N | N | N | N |
@-moz-document url-prefix(){} | @-moz-document url-prefix(){ .eq {color:blue;}} | N | N | N | N | Y | N | N | N |
@media screen and (-webkit-min-device-pixel-ratio:0){} | @media screen and (-webkit-min-device-pixel-ratio:0){.eq {color:blue;}} | N | N | N | N | N | N | Y | Y |
@media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0){} | @media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0){.eq {color:blue;}} | N | N | N | N | N | Y | N | N |
body:nth-of-type(1) | body:nth-of-type(1) .eq {color:blue;} | N | N | N | Y | Y | Y | Y | Y |
FF:firefox; OP:opera; SA:safari; CH:chrome; Y表明支持,N表明不支持。ide
.eq { color:#f00;/*標準瀏覽器*/ color:#f30\0;/*IE8,IE9,opera*/ *color:#c00;/*IE7及IE6*/ _color:#600;/*IE6專屬*/ } :root .eq {color:#a00\9;}/*IE9專屬*/ @media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0){.eq {color:#450;}}/*opera專屬*/ @media screen and (-webkit-min-device-pixel-ratio:0){.eq {color:#879;}}/*webkit專屬*/ @-moz-document url-prefix(){ .eq {color:#4dd;}}/*firefox專屬*/