I'm trying to change the background color of a table's rows using CSS, but I do not want to change a table heading's background. However, by default, a TH is wrapped in a TR, so the TR rule is pushed to my TH.
Here's a jsfiddle to test with, if it helps:
http://jsfiddle.net/jomanlk/Bcayc/
The HTML <tr> bgcolor Attribute is used to specify the background color of a table row. It is not supported by HTML 5. Attribute Values: color_name: It sets the background color by using the color name.
Changing the Background Color of a Cell To change the color of a row, you can add the “style” property into the <td> brackets and define the color of the cell from there.
Cell background colors are set by applying the bgcolor attribute to a <tr> tag (to color the row) or to a <td> tag (to color the cell).
You can add <thead>
and <tbody>
to differenciate your header rows from the data rows. This way you can target only the desired ones:
table tbody td:hover{
background: #f00;
}
table tbody tr:hover{
background: #00f;
}
DEMO
Along with the following markup:
<table>
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Col 1</td>
<td>Col 2</td>
<td>Col 3</td>
<td>Col 4</td>
</tr>
</tbody>
</table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With