【发布时间】:2014-04-17 11:21:32
【问题描述】:
在以下代码中使用p:nth-child(1) 时,第一段不会被选中:
p:nth-child(1) {
background:#ff0000;
}
<h1>Unrelated</h1>
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
查看jsBin
但是当删除 h1 时它可以工作,请参阅此 jsBin
知道为什么吗?
【问题讨论】:
-
nth-child()和nth-of-type()- fiddle 有区别 -
好的,谢谢大家,我不知道
nth-of-type()。
标签: html css css-selectors