css3 - Is it possible to select nth-child(x) but only if it is not the last child? -
i want select third element within ul
, if not last element in ul
.
sample 1:
<ul> <li>home</li> <li>cat 1</li> <li>subcat 1</li> <li>product</li> </ul>
sample 2:
<ul> <li>home</li> <li>cat 1</li> <li>product</li> </ul>
i want single css selector, which, sample 1, selects li
"subcat 1", , sample 2, not select anything.
ul > li:nth-child(3)
work sample 1, match 'product' li in sample 2, don't want do.
in case i'm not able modify html.
you use :nth-child :not achieve need. here example.
ul li:nth-child(3):not(:last-child) { color: red; }
<ul class="sample1"> <li>home</li> <li>cat 1</li> <li>subcat 1</li> <li>product</li> </ul> <ul class="sample2"> <li>home</li> <li>cat 1</li> <li>product</li> </ul>
Comments
Post a Comment