How do I apply specific css styling to every (for the sake of argument) odd element in a set of elements, while taking into account a set of excluded elements?
The issue is replicated here (shown in a codepen):
http://codepen.io/houdmont/pen/VLOBBG
A series of elements which have a class .foo
applied:
<a href="#" class="foo">1. Blue</a>
<a href="#" class="foo">2. Green</a>
<a href="#" class="foo">3. Blue</a>
<a href="#" class="foo bar">4. Hidden (blue)</a>
<a href="#" class="foo bar">5. Hidden (blue)</a>
<a href="#" class="foo bar">6. Hidden (blue)</a>
<a href="#" class="foo">7. Green</a>
When the .bar
class is applied, the element is hidden.
I'd like the remaining elements with .foo
applied to be styled odd/even.
Attempt as follows:
.bar {
display: none;
}
/**
* This clearly doesn't work as I'd hoped it would.
*/
.foo:not(.bar):nth-of-type(even) {
color: green;
}
Ideally, I'd like the seventh element to be green, even though it's an "odd" element, if I were able to exclude the elements with class .bar
then it would be the fourth element and therefore considered "even", setting the color to green.
Is this possible with CSS?