简体   繁体   English

not()和第一个子选择器之间的特异性

[英]Specificity between not() and first-child selectors

So we have the following example about not() and p:first-child{} selectors.Here is the example: 因此,我们有以下关于not()p:first-child{}选择器的示例。这里是示例:

<!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>

Why the paragraph is red at the end? 为什么段落末尾是红色? Can somebody explain (if possible ) why the p:first-child{} has bigger specificity than not() selector??? 有人可以解释(如果可能的话)为什么p:first-child{}not()选择器具有更大的特异性吗???

Can somebody explain (if possible ) why the p:first-child{} has bigger specificity than not() selector? 有人可以解释(如果可能的话)为什么p:first-child {}比not()选择器具有更大的特异性吗?

Because :not() doesn't have any influence on specificity itself – only what is inside it counts in regard to specificity. 因为:not()本身对特异性没有任何影响-只有内部的才算特异性。

So you have the element selector p and the pseudo class :first-child , which gives a specificity of 0-0-1-1 – and you have the element selectors p and a , which result in 0-0-0-2 . 因此,您具有元素选择器p和伪类:first-child ,其特异性为0-0-1-1 –并且您具有元素选择器pa ,其结果为0-0-0-2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM