【发布时间】:2014-03-11 12:19:27
【问题描述】:
我有一个带有标题和一些部分的简单 HTML。
<header>Header</header>
<section>Section 1</section>
<section>Section 2</section>
<section>Section 3</section>
我想为第一部分设置样式
section:first-child {
background-color:green;
}
当存在header (jsfiddle) 时,:first:child 选择器似乎不起作用。当我删除 header 时,一切都恢复正常了!为什么?
【问题讨论】:
-
对于旧浏览器,
.parent > section:first-child, .parent > header:first-child + section -
@Mr_Green 有用的补充,谢谢!
标签: css css-selectors