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>
答案 0 :(得分:5)
<p>
标签不能嵌套在HTML中。这是因为它们仅存在以将文本格式设置为....段落,您可以阅读有关here的更多信息。
简而言之,无论语法如何,任何打开的<p>
标签都会关闭最后一个打开的<p>
标签。