not()和first-child选择器之间的特异性

Agg*_*nos 1 html css css-selectors css-specificity

所以我们有以下关于not()p:first-child{}selectors的例子.这是一个例子:

<!DOCTYPE html>
<html>
<head>
<style>
p:first-child{
color: red;
}
p:not(a){
    color: green;
}
</style>
</head>
<body>

<p>This a paragraph.</p>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

为什么段落最后是红色的?有人可以解释(如果可能的话)为什么 p:first-child{}not()选择器具有更大的特异性???

CBr*_*roe 5

有人可以解释(如果可能的话)为什么p:first-child {}比not()选择器具有更大的特异性?

因为:not()对特异性本身没有任何影响 - 只有内部的内容才具有特异性.

所以,你必须在元件选择p和伪类:first-child,它给人一种特异性0-0-1-1-和你的元素选择pa,这导致0-0-0-2.