As already mentioned, the first child works as expected, as the first child of the parent.
The first-child selector is used to select the specified selector only if it is the first child of its parent.
Source: CSS: first parent selector
You can achieve the first .blue as follows:
.red + .blue
or if you want to get all .blue after .red
.red ~ .blue
, : first-of-type, , .blue HTML.
div.red:first-of-type {
color:#F00;
}
div.red:last-of-type {
color:#00F;
}
p.blue:first-of-type {
color:#F00;
}
p.blue:last-of-type {
color:#00F;
}
<div>
<div class="red">one</div>
<div class="red">two</div>
<div class="red">three</div>
<p class="blue">one</p>
<p class="blue">two</p>
<p class="blue">three</p>
</div>
Hide result