not()和第一个子选择器之间的特定性 [英] Specificity between not() and first-child selectors
问题描述
因此,我们有以下关于 not()
和 p:first-child {}
selectors.Here是示例:
<!DOCTYPE html>
< html>
< head>
< style>
p:first-child {
color:red;
}
p:not(a){
color:green;
}
< / style>
< / head>
< body>
< p>这是一个段落。< / p>
< / body>
< / html>
为什么段落最后是红色的?可以有人解释为什么 p:first-child {}
比 not()
有人可能解释为什么p:first-child { }因为:not()对特异性本身没有任何影响 - 只有一个
所以你有元素选择器
p
和伪类:first-child
,它给出了0-0-1-1
的特殊性 - 并且有元素选择器p
和a
,这导致0-0-0-2
。So we have the following example about
not()
andp:first-child{}
selectors.Here is the example:<!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 thannot()
selector???解决方案Can somebody explain (if possible ) why the p:first-child{} has bigger specificity than not() selector?
Because :not() doesn’t have any influence on specificity itself – only what is inside it counts in regard to specificity.
So you have the element selector
p
and the pseudo class:first-child
, which gives a specificity of0-0-1-1
– and you have the element selectorsp
anda
, which result in0-0-0-2
.这篇关于not()和第一个子选择器之间的特定性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!