Specificity between not() and first-child selectors

蓝咒 提交于 2019-12-11 11:13:57

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/36610048/specificity-between-not-and-first-child-selectors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!