有没有办法只针对选定父母的某些孩子而不复制孩子选择器并使选择器在长度方面超出图表?
例如,我想选择某些 div 的第一个子段落。
CSS就像
.funny > p:first-child, .sad > p:first-child {
color: red
}
标记
<div class="funny">
<p>This is red</p>
<p>This is whatever</p>
<p>This is whatever</p>
<p>This is whatever</p>
</div>
<div class="wildcrazy">
<p>This is whatever</p>
<p>This is whatever</p>
<p>This is whatever</p>
<p>This is whatever</p>
</div>
<div class="sad">
<p>This is red</p>
<p>This is whatever</p>
<p>This is whatever</p>
<p>This is whatever</p>
</div>
显然,除了我想要定位的有趣和悲伤之外,许多其他 div 中可能还有很多其他第一段,也可能有很多其他 div,比如我不想定位的 wildcrazy 。
我的问题是:我可以如何声明孩子并将其与所有父母一起添加吗?就像是:
.funny, .sad, .another_div_class0, .another_div_class1, .another_div_class2, .another_div_class3 > p:first-child
代替
.funny p:first, .sad p:first-child, .another_div_class0 p:first-child, .another_div_class1 p:first-child, .another_div_class2 p:first-child, .another_div_class3 p:first-child