Forum Moderators: open

Message Too Old, No Replies

Slaving a hover effect into another table cell

         

Legacy777

8:31 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



I'm not sure if what I'm trying to do is possible, but here it goes. I am using a style header to control mouse rollover text decoration. I have a table setup with two columns. There is text in each column that is linked to another page. Both text elements in each cell of the table go to the same link.

What I would like to have happen is when you run the mouse over one of the cells, the text decoration occurs for both cells. Currently they react independently of each other.

Here's the code for the style header and table


<style type="text/css">
A { text-decoration: underline; color: #000000}
A:hover { text-decoration: none; color: #0000CC}
</style>


<tr>
<td width="15%" align="center" height="20"><font face="Arial" size="2">
<b><a href="Volumes/01_Default.htm" target="_parent">01</a></b></font>
</td>
<td width="85%" height="20"><font face="Arial" size="2">
<b><a href="Volumes/01_Default.htm" target="_parent">Design Manual Use and Organization</a></b></font>
</td>
</tr>

Thanks in advance for any help.

Josh

tedster

6:33 am on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This kind of functionality (action in one table cell affects another table cell) is possible, but it would require javascript and CSS (DHTML) - and that would limit accessibility.

Could you use a colspan, making these two cells into one? It would depend on your particular page - but if you can, then having everything in one double-wide cell might allow you to wrap both elements into one anchor tag. If so, then no javascript needed.

Legacy777

1:21 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



I did look at colspan, however the reason each element is in their own column is due to spacing and alignment on the page. I'm not sure how I would retain the spacing/alignment and combine the columns. If you have any suggestions, I'm all ears.

As for using javascript & css limiting use. What browsers would be affected. This is an internal company specs page. We do currently use css & I think there's some javascript. We mainly have IE5+, however some people do have ipaqs that may be accessing the page.

Do you have an example of this functionality that you could point me to, so that I can take a look at the code.

Thanks
josh

tedster

6:33 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Small screen browsers may not support javascript, but I was pointing more to people who intentionally turn js off. If you are working with an in-house application, then you are probably fine.

Using javascript, the idea is this:

1. give each slaved anchor a unique ID
2. this allows you to address that anchor's properties, so you can
3. change the class of the slaved anchor when there is a hover of the original
4. do this twice, so you have the effect working both ways

<html>
<head>
<title>Untitled</title>
<style typer="text/css">
a:link {text-decoration:underline;color:#000000;}
a:hover {text-decoration:none;color:#0000cc;}
a.hvr:link {text-decoration:none;color:#0000cc;}
</style>
</head>

<body>
<table cellpadding="10" border="1">
<tr>
<td><a href="#" id="slaved1" onMouseOver="document.getElementById('slaved2').className='hvr'" onMouseOut="document.getElementById('slaved2').className=';'">Link text one</a></td>
<td><a href="#" id="slaved2" onMouseOver="document.getElementById('slaved1').className='hvr'" onMouseOut="document.getElementById('slaved1').className=';'">Link text two</a></td>
</tr>
</table>
</body>
</html>

kaled

7:43 pm on Mar 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If both links are on the same row, it may be possible to adapt Tedster's method to adjust the style of the <tr>. Of course, this may not be what you want.

You might also consider setting { display:block } for each link. This would make the whole table cell clickable as a link (assuming the table cell has no other content).

Kaled.

jollymcfats

8:13 pm on Mar 2, 2005 (gmt 0)

10+ Year Member



There's also a DHTML library that might be useful: try a google search for "X Table Toys".

I've never used the library myself, but I've always thought the demo was pretty nifty.

Legacy777

4:05 am on Mar 3, 2005 (gmt 0)

10+ Year Member



Thanks everyone for the suggestions.

When I get back in the office I'll try one of those solutions.

Josh

Legacy777

7:01 pm on Mar 7, 2005 (gmt 0)

10+ Year Member



I tried tedster's method. It seemed to work at first, but as soon as you click the link, and go back, they no longer have linked hover properties.

Any ideas why it's doing that?

Thanks
Josh

kaled

8:20 pm on Mar 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe that if you ensure a:hover effects are declared AFTER a:visited effects, that should fix the problem. That said, I am definitely not a CSS guru.

Kaled.

Legacy777

4:10 pm on Mar 8, 2005 (gmt 0)

10+ Year Member



I've messed around with it some more, and it doesn't seem to work repeatedly. After you have clicked on the link, they don't link together any more.