我希望p:nth-child(2)
突出显示的第二项p
,即第二段,但是为什么在这种情况下突出显示第一段呢?我删除了h1
,p:nth-child(2)
突出显示了第三项,为什么?h1也考虑p
吗?
p:nth-child(2) {
background: #ff0000;
}
<h1>test</h1>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
p:nth-child(2)
表示如果p
是集合中的第二个元素,则将其突出显示。使用p:nth-of-type(2)
要突出确切第二p
的组合集合中元素p
和h1
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句