I have the following markup:
<div class="foo">
<ul>
<li>one</li>
<li>two</li>
</ul>
<ul>
<li>three</li>
</ul>
<ul>
<li>four</li>
</ul>
</div>
I wish to style "one" and "three".
However, the markup could also be:
<div class="foo">
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
<ul>
<li>four</li>
</ul>
</div>
I've tried using the following CSS:
.foo li:nth-child(1),
.foo li:nth-child(3)
{
color:red;
}
However, as expected, this is styling the first child of each ul
. (Demo: http://jsfiddle.net/hTfVu/)
How can I change my CSS so that I can target the 1st and 3rd li
belonging to .foo
?