I have a problem with CSS :nth-of-type selector. In my code I have a list of DIVs (class "item") that should have an alternating background-color (eg. red and green). Between these items there can be some other items (class "noitem") that should not be matched from the background-color.
Problem is now, that the :nth-of-type rule breaks on every of these non-matching elements. that causes that you have one red item after the other...
Example HTML Code:
<div class="row">
<div class="item"><h2>Item</h2></div>
<div class="item"><h2>Item</h2></div>
<div class="noitem"><h2>No Item</h2></div>
<div class="item"><h2>Item</h2></div>
<div class="item"><h2>Item</h2></div>
<div class="item"><h2>Item</h2></div>
<div class="item"><h2>Item</h2></div>
<div class="noitem"><h2>No Item</h2></div>
<div class="item"><h2>Item</h2></div>
<div class="item"><h2>Item</h2></div>
</div>
CSS:
h2{
font-size: 14px;
margin: 0 0 10px 0;
padding: 0;
}
.row .item:nth-of-type(even) h2{
background-color: red;
}
.row .item:nth-of-type(odd) h2{
background-color: green;
}
Can anybody help? Running example of that can be found here: http://jsfiddle.net/5qnjshg7/