Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table cell with CSS 1

Status
Not open for further replies.

Bravogolf

Programmer
Nov 29, 2002
204
GB
Hi,
I have a table cell that does the following:

Code:
<td onMouseover="this.style.backgroundColor='#CCCCCC';" onMouseout="this.style.backgroundColor='#f7f8fc';">

Basically, it changes the background colour upon mousover (apologies for being patronising).

What I would like it to do is

Code:
<td class="mouseovercell">

And in that CSS style, I could have the specified mouseover and mouseout events. Problem is, I dont know how to do this, I can specify the background colours, borders etc. But I cant get it to specify what color to change to when the mouse moves over the table cell (not a link, but the actual table cell).

I apologise in advance if this is a stupid question :)
 
Thanks ggriffit, I got the code from that site.
However, is there any way the color (or even better, the mouseover events) can be specified from a CSS file and not a script?

You see, the color of the table cell will vary depending on what style sheet is selected....
 
Vragabond,

Perchance is that answer elsewhere as well? I'm looking for the answer to this same question, but that link is no longer functional.

Here's hoping! :)
 
You can do it in pure CSS like this:
Code:
.mouseovercell {
   background-color: #f7f8fc;
}

.mouseovercell:hover {
   background-color: #CCCCCC;
}
Unfortunately it only works in Firefox and other modern browsers. To get the same effect in IE, you need to either...
[ul]
[li]Put an <a> element inside the cell with [tt]display:block[/tt] and apply the hover pseudoclass to that instead (I use a similar approach on my website).
[/li]
[li]Use Dean Edwards' IE7 script on your site - you can get it from [/li]
[/ul]

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top