Styling specific columns and rows in table - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Column Layout

Description

Styling specific columns and rows in table

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">

table {<!-- w w  w .j a  va  2  s  .  co m-->
   width: 100%;
   border: 1px solid #CCC;
}
td {
   border: 1px solid #CCC;
}
tr:nth-child(even){
   background: #EEEEEE;
}
tr:nth-child(odd) {
   background: red;
}
td:nth-child(2), td:nth-child(3), td:nth-child(4) {
   text-align: center;
}


      </style> 
 </head> 
 <body> 
  <table> 
   <tbody> 
    <tr> 
     <td>Col 1</td> 
     <td>Col 2</td> 
     <td>Col 3</td> 
     <td>Col 4</td> 
     <td>Col 5</td> 
    </tr> 
    <tr> 
     <td>Col 1</td> 
     <td>Col 2</td> 
     <td>Col 3</td> 
     <td>Col 4</td> 
     <td>Col 5</td> 
    </tr> 
    <tr> 
     <td>Col 1</td> 
     <td>Col 2</td> 
     <td>Col 3</td> 
     <td>Col 4</td> 
     <td>Col 5</td> 
    </tr> 
    <tr> 
     <td>Col 1</td> 
     <td>Col 2</td> 
     <td>Col 3</td> 
     <td>Col 4</td> 
     <td>Col 5</td> 
    </tr> 
    <tr> 
     <td>Col 1</td> 
     <td>Col 2</td> 
     <td>Col 3</td> 
     <td>Col 4</td> 
     <td>Col 5</td> 
    </tr> 
   </tbody> 
  </table>  
 </body>
</html>

Related Tutorials