Style last li using li:nth-child(odd) and li:nth-child(even) - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:nth-child

Description

Style last li using li:nth-child(odd) and li:nth-child(even)

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
ul#myContactList {
   list-style-type:none;
   padding:0;
   border:2px solid Chartreuse;
}

ul#myContactList>li:nth-child(odd) {
   background:yellow;
   color:blue;
}

ul#myContactList>li:nth-child(even) {
   background:pink;
   color:OrangeRed;
}

ul#myContactList>li>ul {
   list-style-type:none;
   padding:0;
   overflow:hidden;
}

ul#myContactList>li>ul>li {
   float:left;
   line-height:33px;
   width:100px;
   padding:0 11px;
   font-weight:bold;
   font-size:0.9em;
}
</style> <!-- w  w  w  .j a  v  a2  s  .c o  m-->
 </head> 
 <body> 
  <ul id="myContactList"> 
   <li> 
    <ul> 
     <li>Lore</li> 
     <li>Lor</li> 
     <li>Lore</li> 
     <li>Lor</li> 
    </ul> </li> 
   <li> 
    <ul> 
     <li>L</li> 
     <li>L</li> 
     <li>L</li> 
     <li>Lore</li> 
     <li>Lorem ipsum dol</li> 
    </ul> </li> 
   <li> 
    <ul> 
     <li>L</li> 
     <li>L</li> 
     <li>Lo</li> 
     <li>Lore</li> 
    </ul> </li> 
   <li> 
    <ul> 
     <li>L</li> 
     <li>L</li> 
     <li>L</li> 
     <li>Lore</li> 
    </ul> </li> 
  </ul>  
 </body>
</html>

Related Tutorials