tags:

views:

153

answers:

3

I want the "tr" that's currently hovered over to change color, and then change back when the mouse is no longer over it. Is this possible using pure CSS, or is javascript the only solution? (I currently have a javascript solution, so I don't need examples of that)

Thanks!

+1  A: 

I believe that javascript is the only solution that will provide cross-browser support.

Plan B
+17  A: 

Yes, this is possible in CSS. The example below will have a red background normally, and a green background when the row is hovered over.

tr td { background: #f00; } 
tr:hover td { background: #0f0; }

However, it should be noted that this will not work in IE6, as it does not understand the ":hover" pseudo class on any elements other than <a>.

Rich Adams
Keep in mind that the majority of the browser market share is held by IE6. I would avoid this if your audience is "anyone."
Plan B
Actually, IE7 has the biggest market share at the moment (http://marketshare.hitslink.com/browser-market-share.aspx?qprid=2). But yeah, IE7 doesn't support :hover properly either.
Rich Adams
Untrue - the above code worked in my IE7 Browser when the page's doctype was: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Pwninstein
I didn't say it wasn't supported in IE7, just that it's not supported "properly". Sometimes IE7 will maintain the hover state if you mouseout with the button held down, and there's issues with nesting :hover (http://murphy.cz/ie7-hover-ghosts-bug/), etc
Rich Adams
I see, thanks for the clarification, and the link!!
Pwninstein
+1 for correct technique. I usually punish IE6 users by leaving things like hover out but if you want to make it work in IE6 too search for css hover htc.
Darko Z
A: 

I think you can use :hover css attribute.

Aif