最后作者给出了最佳方式:
IE 6 and below
Use * html {} to select the html element.
IE 7 and below
Use *+html, * html {} to select the html element.
IE 7 only
Use *+html {} to select the html element.
IE 7 and modern browsers only
Use html>body {} to select the body element.
Modern browsers only (not IE 7)
Use html>/**/body {} to select the body element.
[size=x-small]區別IE和Firefox[/size]
#tip {
background:blue; /*Firefox 背景變藍色*/
background:red \9; /*IE6、IE7、IE8背景變紅色*/
}
【說明】:因為IE瀏覽器看得懂「\9」,但是非IE的瀏覽器一律看不懂,因此就可以用這個語法來區分IE和Firefox(非IE瀏覽器,像是Opera、Google Chrome、Safari等),因此以上CSS範例中,非IE瀏覽器是顯示藍色背景,IE系列瀏覽器是顯示紅色背景。
[size=x-small]區別IE6、IE7、IE8、Firefox[/size]
#tip {
background:blue; /*Firefox 背景變藍色*/
background:red \9; /*IE8 背景變紅色*/
*background:black; /*IE7 背景變黑色*/
_background:orange; /*IE6 背景變橘色*/
}
【說明】:因為IE系列瀏覽器可讀「\9」,而IE6和IE7可讀「*」(米字號),另外IE6可辨識「_」(底線),因此可以依照順序寫下來,就會讓瀏覽器正確的讀取到自己看得懂得CSS語法,所以就可以有效區分IE各版本和非IE瀏覽器(像是Firefox、Opera、Google Chrome、Safari等)。
本文介绍了一种使用CSS选择器和特定语法来区分不同版本Internet Explorer浏览器和其他现代浏览器如Firefox的方法。通过特殊的CSS属性,例如9、* 和 _,可以实现针对IE6、IE7、IE8及非IE浏览器(如Firefox、Opera、Google Chrome和Safari)的样式定制。

被折叠的 条评论
为什么被折叠?



