I need the style to alternate when classes are nested in a repeating pattern. Sadly right now, all the code does is override based on the order of the CSS and not the order of the HTML.
In the example below, each word needs to be the color it names. This needs to work for an indefinite number of nestings (could be a crazy huge number of nestings), and also needs to work when other CSS styles are applied, which means that the HTML cannot be changed. Also, there is no guarantee that there won't be anything between those elements which means they won't be direct parents all the time (So the > selector will not work).
Anyone know how to do this? (Or if it is even possible?)
span {
color: black;
}
.foo a {
color: red;
}
.bar a {
color: green;
}
<html>
<body>
<span class="foo">
<span class="bar">
<span class="foo">
<span class="bar">
<span class="foo">
<span class="bar">
<strong>black <a href="http://example.org">green</a></strong>
</span>
<strong><br>black <a href="http://example.org">red</a></strong>
</span>
<strong><br>black <a href="http://example.org">green</a></strong>
</span>
<strong><br>black <a href="http://example.org">red</a></strong>
</span>
<strong><br>black <a href="http://example.org">green</a></strong>
</span>
<strong><br>black <a href="http://example.org">red</a></strong>
</span>
</body>
</html>