The CSS is being applied the correct way, but I think your understanding of how the rules work may be slightly off. You're selecting the first child of all div
s with class multiple-alerts
which also has the class of normal
. Well, the first child of multiple-alerts
does not have the class normal
(at least in the snippet you included), so your selector matches exactly zero elements.
Now, you may be tempted to go for something like first-of-type
, but that only applies to tags, not classes. So, here's a workaround that you might find useful:
Let's say the standard colour for these span
s is black, we will set all the span
s inside .normal
with yellow colour, then override it for all but the first one, like so:
div.multiple-alerts .normal span {
color: yellow;
}
div.multiple-alerts .normal ~ .normal span {
color: black;
}
If you're not sure how this is working here, the ~
works similarly to the +
, but is broader. The +
can only match with the very next sibling, whereas the ~
can match with any succeeding sibling - i.e. after, but not before.