2
我試圖弄清楚爲什麼.x
比*.x
具有更高的特異性,因爲後者有望獲勝。CSS通用選擇器(*)特異性
是不是*.x
應該有一個具體的0-0-1-1
(1類,1標籤),而.x
只是一個類0-0-1-0
?
考慮以下基本代碼:
*.x { color: blue; }
.x { color: red }
<p class="x">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque, nam.</p>
它應該是藍色的。爲了演示預期的行爲,我代替*
與其他元素(p
):
p.x { color: blue; }
.x { color: red }
<p class="x">This time it works.</p>
通用選擇器的特異性爲0,0,0,0您看不到*作爲標記。在你的情況下,兩者都是平等的... – Yoeri