關於CSS權重的筆記

關於權重的計算,在W3C的網頁上的介紹是:

A selector’s specificity is calculated as follows

  • count the number of ID selectors in the selector (= a)
  • count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= b)
  • count the number of type selectors and pseudo-elements in the selector (= c)
  • ignore the universal selector

翻譯一下

  • id的數量為a(ex. #main #sidebar {…} 這樣是2)
  • class, attr, 偽類別的數量為b
  • tag跟偽元素的數量為c( li:hover:before {…} 這樣是3)
  • 星號直接無視
閱讀全文 關於CSS權重的筆記