Cell Color Swap on Hover

M

Marcia

Is there a way to make an entire cell change color when
you hover? For example: If I were to type in the
word "Click Here" in a cell. Instead of having the
hyperlinked text change color, the background changes
color.

If so, is there a way code it in a style sheet.

Thanks,
Marcia
 
K

Köck Matthias

Hello,
Is there a way to make an entire cell change color when
you hover? For example: If I were to type in the
word "Click Here" in a cell. Instead of having the
hyperlinked text change color, the background changes
color.
If so, is there a way code it in a style sheet.
Well, I've heard that some browsers accept
td:hover { background-color:yourColor; }
but I haven't seen any yet.


The MS Internet Explorer accepts this JS-solution:
<script language=javascript>
function mouse(element,status)
{ element.style.backgroundColor=status?"
colorWhenTheMouseIsOverTheCell":"
colorWhenTheMouseIsNotOverTheCell";
}
</script>
.... written in one line, of course. Example:
yellow if the mouse is about it, blue it it isnt:
element.style.backgroundColor=status?"blue":"yellow";

Change the table cell code into:
<td [other attributes] onmouseover=mouse(this,true)
onmouseout=mouse(this,false)>text within the cell</td>

I don't know how many other browsers do also accept this
solution. If I'm right, Netscape needs:
element.backgroundColor=...;

Köck Matthias
 
J

Jon

Hi,
I've never seen that before but i think this would be better done with CSS
then it should work in anything(except nn4 of course)
<style type="text/css">
#links td{
background-color:red;
padding:0;
}
#links a{
/*/*/display:block;
bacground-color:red;
position:relative;/**/
color: #fff;
}
#links a:hover{
background-color: blue;
}
</style>
<title>Untitled</title>
</head>

<body>
<table id="links" border=0 cellspacing=4 cellpadding=4>
<tr>
<td width=125><a href="#">Link One</a></td>
<td width=125><a href="#">Link Two</a></td>
</tr>
</table>

Obviously there's plenty of scope to pretty this up.

Jon
Microsoft MVP - FP

Hello,
Is there a way to make an entire cell change color when
you hover? For example: If I were to type in the
word "Click Here" in a cell. Instead of having the
hyperlinked text change color, the background changes
color.
If so, is there a way code it in a style sheet.
Well, I've heard that some browsers accept
td:hover { background-color:yourColor; }
but I haven't seen any yet.


The MS Internet Explorer accepts this JS-solution:
<script language=javascript>
function mouse(element,status)
{ element.style.backgroundColor=status?"
colorWhenTheMouseIsOverTheCell":"
colorWhenTheMouseIsNotOverTheCell";
}
</script>
.... written in one line, of course. Example:
yellow if the mouse is about it, blue it it isnt:
element.style.backgroundColor=status?"blue":"yellow";

Change the table cell code into:
<td [other attributes] onmouseover=mouse(this,true)
onmouseout=mouse(this,false)>text within the cell</td>

I don't know how many other browsers do also accept this
solution. If I'm right, Netscape needs:
element.backgroundColor=...;

Köck Matthias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top