Style alternate rows with different color - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:nth-child

Description

Style alternate rows with different color

Demo Code

ResultView the demo in separate window

<html lang="en">
 <head> 
  <title>Some Title</title> 
  <style type="text/css">
.table {<!--   www.  j  a  va 2  s  .com-->
   width:301px;
}

.table span {
   display:inline-block;
   width:31%;
   border:2px solid Chartreuse;
}

.row:nth-child(odd) {
   background-color:yellow;
}

.row:nth-child(even) {
   background-color:blue;
}
</style> 
 </head> 
 <body> 
  <div class="table"> 
   <div class="row"> 
    <span>stuff</span> 
    <span>stuff</span> 
    <span>stuff</span> 
   </div> 
   <div class="row"> 
    <span>stuff</span> 
    <span>stuff</span> 
    <span>stuff</span> 
   </div> 
   <div class="row"> 
    <span>stuff</span> 
    <span>stuff</span> 
    <span>stuff</span> 
   </div> 
   <div class="row"> 
    <span>stuff</span> 
    <span>stuff</span> 
    <span>stuff</span> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials