Nth-child to alternate by 2 rows - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:nth-child

Description

Nth-child to alternate by 2 rows

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">
tr {<!--from www .j a va 2 s  .  c om-->
   background:blue;
}

tr:nth-child(4n+1) {
   background:red;
}

tr:nth-child(4n+2) {
   background:red;
}
</style> 
 </head> 
 <body> 
  <table> 
   <tbody> 
    <tr id="a"> 
     <td>L</td> 
    </tr> 
    <tr id="a"> 
     <td>L</td> 
    </tr> 
    <tr id="b"> 
     <td>L</td> 
    </tr> 
    <tr id="b"> 
     <td>L</td> 
    </tr> 
    <tr id="a"> 
     <td>L</td> 
    </tr> 
    <tr id="a"> 
     <td>L</td> 
    </tr> 
    <tr id="b"> 
     <td>L</td> 
    </tr> 
    <tr id="b"> 
     <td>L</td> 
    </tr> 
   </tbody> 
  </table>  
 </body>
</html>

Related Tutorials