I have 5 divs, every second div should have a different colour than the others.
<div class="element element1">Element1</div>
<div class="element element2">Element2</div>
<div class="element element3">Element3</div>
<div class="element element4">Element4</div>
<div class="element element5">Element5</div>
In my CSS I have
.element {
background-color: grey;
}
.element:nth-child(odd) {
background-color: pink;
}
Now dynamically the order of those elements will change, which I want to do with flexbox. Meaning my CSS looks like this then:
.element {
background-color: grey;
display:flex;
}
.element5 {
order: 1;
}
.element2 {
order: 2;
}
As flexbox is not changing the DOM, the nth-child(odd) will still style every second DOM Element, which is not the order the user will see. But that's what I want. Every second element the users sees should have a different colour, even if the element changes the order with flexbox. Has anyone an idea how this could work? I can only use CSS or HTML for this, no JavaScript or PHP.