?
本文檔使用 php中文網(wǎng)手冊 發(fā)布
<hack> selector{ sRules }
盡可能減少對CSS Hack的使用。Hack有風險,使用需謹慎
通常如未作特別說明,本文檔所有的代碼和示例的默認運行環(huán)境都為標準模式。
一些CSS Hack由于瀏覽器存在交叉認識,所以需要通過層層覆蓋的方式來實現(xiàn)對不同瀏覽器進行Hack的。
簡單列舉幾個:
* html .test { color: #090; } /* For IE6 and earlier */ * + html .test { color: #ff0; } /* For IE7 */ .test:lang(zh-cmn-Hans) { color: #f00; } /* For IE8+ and not IE */ .test:nth-child(1) { color: #0ff; } /* For IE9+ and not IE */
* 上述代碼中的3,4兩行就是典型的利用能力來進行選擇的CSS Hack。
<!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta charset="utf-8" /> <title>選擇符級Hack_CSS參考手冊_web前端開發(fā)參考手冊系列</title> <meta name="author" content="Joy Du(飄零霧雨), dooyoe@gmail.com, www.doyoe.com" /> <style> * html .test { color: #090; } * + html .test { color: #ff0; } .test:lang(zh-cmn-Hans) { color: #f00; } .test:nth-child(1) { color: #0ff; } </style> </head> <body> <div class="test">在不同瀏覽器下看看我的顏色吧</div> </body> </html>
點擊 "運行實例" 按鈕查看在線實例