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

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -