My DOM structure is generated by a JS framework and may appear like this:
span:nth-child(odd) { background-color: lightblue; }
span {
display: block;
}
<div id="parent">
<div class="child">
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
</div>
<div class="child">
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
</div>
<div class="child">
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
</div>
<div class="child">
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
<span>Some text to color in alternate colors with the previous span no matter if it's the same parent or not</span>
</div>
<div class="child">
<span>Some text to color in alternate colors</span>
</div>
</div>
I am attempting to alternate the color of the spans regardless of whether the parent element is the same or not. I have tried using pseudo selectors and referencing a question on CSS div alternating color, but had no success. Is achieving this solely with CSS possible, or should I consider a solution involving a JS framework?