條件注釋相關說明

參考文章:關于條件注釋的幾個實例代碼

如果要針對IE6、IE7、IE8下不同的css,有很多種方法,目前我是用特殊字元的方式(在樣式前面加上*、_、 或尾巴加\8)。因為做起來最省事。但是這種作法的缺點是無法通過W3C CSS驗證

那如果想要通過驗證,就得用【條件注釋】的方法來做。

應用方式如下
<link rel=”stylesheet” media=”all” type=”text/css” href=”style.css” />
<!–[if lte IE 6]>
<link rel=”stylesheet” media=”all” type=”text/css” href=”style-ie6.css” />
<![endif]–>
<!–[if lte IE 7]>
<link rel=”stylesheet” media=”all” type=”text/css” href=”style-ie7.css” />
<![endif]–>
<!–[if lte IE 8]>
<link rel=”stylesheet” media=”all” type=”text/css” href=”style-ie8.css” />
<![endif]–>

因為條件注釋只有IE看的懂,所以別的瀏覽器不會讀後面的那些樣式檔。