Set background color of table cells - HTML CSS CSS Widget

HTML CSS examples for CSS Widget:Table Cell

Description

Set background color of table cells

Demo Code

ResultView the demo in separate window

<!doctype html>
<html>
 <head> 
  <style type="text/css">
td {<!-- w  ww  . j a va 2s .  co m-->
   background-color:Chartreuse;
}

tr:nth-child(even)>td {
   background-color:yellow;
}

tr>td:first-child {
   background-color:blue;
}
</style> 
 </head> 
 <body> 
  <table width="200" border="1"> 
   <tbody> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
   </tbody> 
  </table>  
 </body>
</html>

Related Tutorials