Reputation: 333
I'm trying to figure out a CSS nth-child formula to target every other child, but always including the last child.
For example:
And so on...
Is this possible with only CSS? I'm okay with using something other than or in addition to nth-child but trying to stay CSS only.
Upvotes: 0
Views: 60
Reputation: 1565
Is this fine for you?
li:nth-last-child(2n+1) {
color: red;
}
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
<ul>
<li>item</li>
<li>item</li>
</ul>
<ul>
<li>item</li>
</ul>
Upvotes: 2