用四位元組 (a, b, c, d) 表示:
style="" (1,0,0,0)#id (0,1,0,0).class [attr] :hover (0,0,1,0)div ::before (0,0,0,1)*:(0,0,0,0) 不增加權重| 選擇器 | Specificity | 說明 |
|---|---|---|
h1 | (0,0,0,1) | 1 元素 |
body h1 | (0,0,0,2) | 2 元素 |
.grape | (0,0,1,0) | 1 類別 |
h2.grape | (0,0,1,1) | 1 類別 + 1 元素 |
#answer | (0,1,0,1) | 1 ID + 1 元素 |
html > body table tr[id="totals"] td ul > li | (0,0,1,7) | 1 屬性 + 7 元素 |
li#answer | (0,1,0,1) | 1 ID + 1 元素 (ID 勝過所有類別/元素) |
style="color:red" | (1,0,0,0) | 內嵌樣式最高 (僅次 !important) |
!important 打破所有,權重最高 (除非對方也 !important 且 Specificity 更高或同樣後寫)!important (作者) < !important (使用者):where() (Specificity 為 0) 降低選擇器權重::where(.container) .btnInline (1000) > ID (0100) > Class/Attr/Pseudo (0010) > Element/Pseudo-el (0001) > * (0000)
!important 破壞規則,慎用。