If I use the following code:
<style>
.a:nth-child(2){
color: blue
}
</style>
<div class="a">Hello</div>
<div class="b">Goodbye</div>
<div class="a">Hello 2</div>
The text of the second div with the classname of 'a' is not changed to the color blue.
However, if I rearrange the divs
<style>
.a:nth-child(2){
color: blue
}
</style>
<div class="a">Hello</div>
<div class="a">Hello 2</div>
<div class="b">Goodbye</div>
This works. How would I get the second div by classname as written in the first example using pure CSS?
Also, the :nth-of-type(n) syntax works exactly the same.
Here's a fiddle demonstrating this: