Select first two list item with :nth-child(-n+2) - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:nth-child

Description

Select first two list item with :nth-child(-n+2)

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">
a {<!--  ww  w .  ja  v a 2  s  .com-->
   text-decoration:none;
   color:Chartreuse;
}

ul li:nth-child(-n+2) {
   color:yellow;
}
</style> 
 </head> 
 <body> 
  <ul> 
   <li>Lorem</li> 
   <li>Lorem </li> 
   <li> <a href="#">Lorem</a> <a href="#">Lorem</a> </li> 
  </ul> 
  <div> 
   <span> <a href="#">Lorem </a> <em>Lorem</em> </span> 
  </div>  
 </body>
</html>

Related Tutorials