Using nth-child to style multiple items - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:nth-child

Description

Using nth-child to style multiple items

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 li:nth-child(1),
ul li:nth-child(3),
ul li:nth-child(7),
ul li:nth-child(8) {
   background-color:Chartreuse;
   color:yellow;
}
</style> <!-- ww w.  j a v a 2  s  .  c  om-->
 </head> 
 <body> 
  <ul> 
   <li>L</li> 
   <li>L</li> 
   <li>L</li> 
   <li>L</li> 
   <li>L</li> 
   <li>L</li> 
   <li>L</li> 
   <li>L</li> 
   <li>L</li> 
  </ul>  
 </body>
</html>

Related Tutorials