此问题已经在这里有了答案:
p标签的CSS伪类选择器(第一个孩子)适用于作为其父对象的直接第一个孩子的所有p,为什么不将p标签作为p本身的直接第一个元素。
p:first-child {
color: blue;
}
<body>
<p>This P is body's first Child.</p>
<p>This is body's second child.</p>
<div>
<p> This P is div's first Child </p>
<p> This is div's second child.</p>
</div>
<p>
<p> This P is P's first child :: Why it does not get pseudo class</p>
<p> This is P's second child </p>
</p>
</body>
<p>
标记不能嵌套在HTML中。这是因为它们仅存在以将文本格式设置为....段落,您可以阅读更多有关here的信息。
简而言之,任何打开的<p>
标记都会简单地关闭要打开的最后一个<p>
,而与语法无关。