0

Alternate Rows with CSS

/*The CSS*/

#sampletable th{
background: silver;
}

#sampletable tr:nth-of-type(odd){ /*odd rows*/
background: lightyellow;
}

#sampletable tr:nth-of-type(even){ /*even rows*/
background: lightblue;
}

#sampletable tr>td:first-of-type{ /*first cell of each row*/
font-weight: bold;
}
 
/* The HTML Code */
 
<table id="sampletable" border="1" width="80%">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>George</td>
<td>30</td>
</tr>
<tr>
<td>Sarah</td>
<td>26</td>
</tr>
<tr>
<td>David</td>
<td>42</td>
</tr>
<tr>
<td>Collin</td>
<td>32</td>
</tr>
</table> 

0 comments:

Post a Comment