我需要在每个部分的第一个子项之后显示单词first
:
section:first-child::after {
content: "first";
}
因为您没有设置元素的父级。CSS 中的所有元素都继承自body
。 在您的示例中,section
处理方式为:
body section: first-child
如果section
元素之前没有任何内容,并且它是body
的第一个子元素,那么它将具有指定的属性。 否则属性将被忽略。
您应该将section
包装到容器中。例如:
<div id="parent">
<section>...</section>
<section>...</section>
</div>
和 CSS:
.parent section:first-child::after {
content: "first";
}