Set background to even rows

Style table tr:nth-child(even) is setting style to every even row. If you want to set style to odd rows you should use nth-child(odd).
<!DOCTYPE html>
<html>
<head>
<style>
table {
background-color:lightgreen;
}
table tr:nth-child(even) {
background-color:lightgreen;
}
table tr:nth-child(odd) {
background-color:green;
}
</style>
<meta charset="UTF-8">
</head>
<body>
<table>
	<tr>
		<th>First H</th>
		<th>Second H</th>
		<th>Third H</th>
	</tr>
	<tr>
		<td>cell </td>
		<td>cell </td>
		<td>cell </td>
	</tr>
	<tr>
		<td>cell </td>
		<td>cell </td>
		<td>cell </td>
	</tr>
	<tr>
		<td>cell </td>
		<td>cell </td>
		<td>cell </td>
	</tr>
</table>
</body>
</html>

Responses

0 Replies