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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

td onclick 2

Status
Not open for further replies.

blitzer

Programmer
Jun 18, 2001
34
CA
Hello All. I like how the CNN.com website has a menu which changes colors with onmouseover but the really cool thing is how you can click anywhere in the td box and it goes to the link.. rather than the usual where you can only click the text. Is there an easy way to do this?
 
<style>
a.menu { display: block; width: 100px; background-color: blue; }
a.menu:hover {background-color: green }
</style>

. . .

<td><a href=&quot;#&quot; class=&quot;menu&quot;>link 1</a></td>

. . .

The key is to us &quot;display: block&quot; - this will create the active link area.
 
thanks but not quite what I was looking for.. I'm looking for something where if you click anywhere in the <td> box you get a link. Like on cnn.com
 
a.submenu {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
color: #FFFFFF;
display: block;
height: 20px;
width: 125px;
text-align: left;
vertical-align: middle;

just make the height and with = the table that the links are in then just assing the class to the links [rockband]
sleep is good
 
o i forgot to add for the rollover add this as well

.submenu {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
color: #FFFFFF;
display: block;
height: 20px;
width: 125px;
text-align: left;
vertical-align: middle;
background-color: #006666;

change the background to whatever you want [rockband]
sleep is good
 
no no no no no and no. I believe what blitzer is talking about is a full TD not only a link.

Here is how you can do it :

<style>
.on { background-color: Teal ; cursor: pointer ;}
.off { background-color: Gray ; }
</style>

<table>
<tr>
<td onmouseover=&quot;this.className='on'&quot; onmouseout=&quot;this.className='off'&quot; class=&quot;off&quot;>Clickable TD</td>
</tr>
</table>

I hope this helps. Gary Haran
 
yes he wants to make the whole cell a link.....you would have to block it off...and i made a mistake my classes should be a.submenu and the secone one should be a.submenu:hover [soapbox]
sleep is good
 
thanks hads. A star for you for correcting my mistake(in the spirit of perfection I give stars to anyone who tells me I am wrong).

I could have sworn I had put that onclick in there somewhere! :) Gary Haran
 
blitzer, if you had tested my proposal you could see that [tt]display: block[/tt] does what you want. Just change the link area size using [tt]width | height[/tt] properties to the desired values.
 
Aggreed, I like that way of doing it too starway. It's nice and clean and doesn't involve any javascript. I have used it on a site.

Doesn't it fall over in NS 4 and I also had problems with it on IE Mac? [smurf]
01101000011000010110010001110011
 
Exactly, the whole point is that it's pure CSS without any scripting at all. Unfortunately, it doesn't work in N4 (therefore I use it only when I'm 100% sure that it's non-N4 environment). But <td onclick> doesn't work there as well.
As for IE on Mac - I tested it on IE5, and it worked as expected.
 
I'm using the xutopia / hads suggestion because in my <td> bar there is more than just text links.. anyway thanks to everyone for their help!
 
My apologies, I didn't read your first post clearly enough starway. I did not realise you had enclosed the <a> inside a <td>.

When I had problems with IE (mac ver.?) and NS4 it was because of them not recognising the display:block and displaying them as inline elements instead which degraded poorly. With the <a> inside a <td> it doesn't effect the layout as such and is a better solution.

Although this doesn't apply to blitzer if he has a <td> full of all sorts of things. [smurf]
01101000011000010110010001110011
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top