I am working with an HTML structure that has a specific layout, and I need to target all odd <span>
elements globally without considering their parent elements.
Is there a way to style 1
, 3
, 5
, 7
, 9
in red color? I attempted to use :nth-child(odd)
but it seems to work locally only.
body {
counter-reset: spans;
}
span {
counter-increment: spans;
}
span::after {
content: counter(spans);
}
span:nth-child(odd) {
color: red;
}
<div>
<span></span>
</div>
<div>
<span></span>
<span></span>
</div>
<div>
<span></span>
<span></span>
<span></span>
</div>
<div>
<span></span>
<span></span>
<span></span>
<span></span>
</div>