I have elements of a given secondclass
with grey background and I would like only even elements of this class with a red background. I can't use nth-child()
selector because these elements might not be the only inside parent.
I've tried the following:
.secondclass {
background-color:#aaa;
}
.secondclass:nth-of-type(2n+1) {
background-color:red;
}
This works fine until I put an element of the same type of secondclass
inside parent (i.e. a div). This is reasonable, since nth-of-type()
refers to the type not the class:
<div>some text</div>
<div class="secondclass"></div>
<div class="secondclass"></div>
Is there a pure-CSS way to select only even elements of secondclass
subset, independently from their type?