not()和第一个子选择器之间的特定性 [英] Specificity between not() and first-child selectors

查看:103
本文介绍了not()和第一个子选择器之间的特定性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我们有以下关于 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() and p: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 than not() 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 of 0-0-1-1 – and you have the element selectors p and a, which result in 0-0-0-2.

这篇关于not()和第一个子选择器之间的特定性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆