Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing background colour of tr element on mouseover

Tags:

html

css

I want to have my table rows highlighted on mouse over, but I have yet to find a way to do it that isn't using Javascript. Is this not possible in CSS?

I've tried this:

tr:hover {     background: #000; } 

But that doesn't work. Using td:hover works, but I want to change the background colour of the whole table row.

Is there a pure CSS/HTML way to do it, or am I going to have to resort to Javascript?

like image 205
Josh Avatar asked Mar 30 '11 21:03

Josh


People also ask

How do I change the background color of a TR tag?

HTML | <tr> bgcolor Attributecolor_name: It sets the background color by using the color name. For example “red”. hex_number: It sets the background color by using the color hex code.

How do I change the hover color?

Changing link color on hover using CSS To change the color of your link on hover, use the :hover pseudo property on the link's class and give it a different color.

How do I change the background color of an element?

How to Add Background Color in HTML. To add background color in HTML, use the CSS background-color property. Set it to the color name or code you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a table, heading, div, or span tag.

How do I change the color of my tr in CSS?

How to color specific row in a CSS Table. You can use the tr:nth-child(rownumber) to color a particular row in a table using CSS. Above code select the 3 row from top (including table head row) and color background as green and foreground as white.


2 Answers

<tr>s themselves are very hard to access with CSS, try tr:hover td {background:#000}

like image 133
Wesley Murch Avatar answered Sep 21 '22 21:09

Wesley Murch


You could try:

tr:hover {     background-color: #000; }  tr:hover td {     background-color: transparent; /* or #000 */ } 

JS Fiddle demo.

like image 30
David Thomas Avatar answered Sep 21 '22 21:09

David Thomas