Select every odd item starting from the 5th place
2 answers
you can use .elem:nth-child(2n+5)
li:nth-child(2n+5) {
color: red
}
<ol>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ol>
2n
will select every other element and +5
will act as an offset. So when n
starting at zero you get 5, 7, 9, 11, ...
+5
source to share
you can use
-
:nth-child(odd)
to select every odd item -
:not(:nth-child(-n + 4))
to not select the first 4 elements
div:not(:nth-child(-n + 4)):nth-child(odd) {
background: red;
}
<div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div>
Or if you want to start from the 5th item you can go to this
div:not(:nth-child(-n + 5)):nth-child(even) {
background: red;
}
<div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div><div>Div</div>
+2
source to share