I need that consecutive classes have alternating colors also when interspersed by other (consecutive) classes.
So the green bb second
in the second picture should have been blue as seen below
need
now
.first{
color: red;
}
.first ~ .second:nth-child(even) {
color: blue;
}
.first ~ .second:nth-child(odd){
color:green;
}
<div class="first">aa first</div>
<div class="second">bb second</div>
<div class="second">bb second</div>
<div class="second">bb second</div>
<div class="first">aa first</div>
<div class="first">aa first</div>
<div class="second">bb second</div>
<div class="second">bb second</div>
Original text
It is necessary that consecutive classes are the first first and the next second was an alternating color, and then when back found first again alternated as the picture classes are in order necessary