[英]CSS Specificity - Conflicts between CSS selectors
I have a question regarding the following pseudo-class selector.我对以下伪类选择器有疑问。 Even with !important
, the text under this li:first-child
is not showing blue.即使使用!important
,此li:first-child
下的文本也不会显示为蓝色。
p has Selector Specificity: (0, 0, 1) li:first-child has Selector Specificity: (0, 1, 1) p 具有选择器特异性:(0, 0, 1) li:first-child 具有选择器特异性:(0, 1, 1)
I am expecting the xyz to be blue but it is red.我期待 xyz 是蓝色的,但它是红色的。 Unless comment out CSS for p (red color).除非注释掉 p(红色)的 CSS。
p { color: red; } li:first-child { color: blue;important: list-style; none; }
<p>abc</p> <aside> <ul> <li> <p>xyz</p> </li> </ul> </aside>
After reviewing the answer, the new code is good:查看答案后,新代码很好:
<html lang="en">
<head>
<title>Test</title>
<style>
p {
color: red;
}
li:first-child p {
color: blue;
list-style: none;
}
</style>
</head>
<body>
<p>abc</p>
<ul>
<li><p>xyz</p></li>
</ul>
</body>
</html>
The li:first-child
makes the color of the <li>
blue, but the <p>
is still red. li:first-child
使<li>
的颜色变为蓝色,但<p>
仍然是红色。
li:first-child
selects the li that is a first child, not the first child of the li. li:first-child
选择作为第一个孩子的li,而不是li 的第一个孩子。
p { color: red; } li:first-child p { color: blue;important: list-style; none; }
<p>abc</p> <aside> <ul> <li> <p>xyz</p> </li> </ul> </aside>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.