Is there a way to target only certain children of select parents without duplicating the children selectors and making the selector go off the charts in terms of length?
For example, I want to select the first-child paragraph of certain divs.
CSS would be like
.funny > p:first-child, .sad > p:first-child {
color: red
}
The markup
<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>
Obviously, there could be loads of other first paragraphs in lots of other divs besides funny and sad that I do want to target, and there could also be loads of other divs like wildcrazy that I do not want to target.
My question is: can I some how declare the child and prepend it with all the parents? Something like:
.funny, .sad, .another_div_class0, .another_div_class1, .another_div_class2, .another_div_class3 > p:first-child
instead of
.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