選擇器類別 | 權重 | 優先級 |
---|---|---|
!important | 1,0,0,0,0 | 最高,全局性 |
元素內樣式style | 1,0,0,0 | 1 |
id選擇器 | 0,1,0,0 | 2 |
類/屬性/偽類 | 0,0,1,0 | 3 |
元素/偽元素 | 0,0,0,1 | 4 |
通配選擇器* | 0,0,0,0 | 5 |
!important是用來使IE6和IE7、IE8、火狐(Firefox)、google等瀏覽器做兼容的,但IE6不能執行!important。
在使用!important時需要注意:
- Never 永遠不要在全站范圍的 css 上使用 !important
- Only 只在需要覆蓋全站或外部 css(例如引用的 ExtJs 或者YUI )的特定頁面中使用 !important
- Never 永遠不要在你的插件中使用 !important
- Always 要優化考慮使用樣式規則的優先級來解決問題而不是 !important