Cells becoming hyperlinks

liunx

Guest
Hello,<br />
How do I make a cell link to another page when I click on it? (For example, I have a cell with no text. I want to be able to simply click on the cell and go to the HTML page of my choice)- before I used this in a frames page (coding below) but I no longer have frames and I just want the hyperlink to load in the same page (sorry if you can't understand that).<br />
<br />
<table border="1" borderColorDark="#000000" borderColorLight="#444444" cellSpacing="0" width="132" height="27"><br />
<tr><br />
<td bgcolor="#444444" style="color: #FFFFFF" onMouseOver="style.color='#FFFFFF'; style.backgroundColor='#992106';" onMouseOut="style.color='#FFFFFF'; style.backgroundColor='#444444';" onClick="parent.main.location.href='http://www.webdeveloper.com/forum/archive/index.php/staff.html'" target="main" height="12" width="122"><a href=http://www.webdeveloper.com/forum/archive/index.php/"staff.html" target="main"><font face="Verdana, Arial, Comic Sans MS" color="#C0C0C0" size="2">Staff</font></a></td><br />
</tr><br />
</table><br />
<br />
<br />
Now, I don't even need to click on the text to go to the HTML page, but with no frames the "parent.main.location.href='http://www.webdeveloper.com/forum/archive/index.php/staff.html'" code seems to be a problem. :( <br />
<br />
<br />
Please help! Thanks!<!--content-->This will only work if javascript is enabled:<br />
<br />
<table border="1"><br />
<tr><br />
<td onclick="window.location.href='http://www.w3c.org'">&nbsp;&nbsp;&nbsp;&nbsp;</td><br />
</tr><br />
</table><!--content-->Thanks it worked- I replaced the "parent.main.location.href" with "window.location.href". Thanks for your help!<!--content-->You're welcome... :)<!--content-->Or you could just do this:<table border="1"><br />
<tr><br />
<td><a href=http://www.webdeveloper.com/forum/archive/index.php/"http://www.w3c.org">&nbsp;&nbsp;&nbsp;&nbsp;</a></td><br />
</tr><br />
</table>Add a class to the link to hide the underline.<!--content-->And doing it that way would really be a better bet... Even if you don't have any text (like you [Rick_Garrison] said) you could add some &nbsp;'s to it to fake it...<!--content-->The beauty of a pure-HTML approach is that if users have JavaScript turned off, they are still able to use the link. I just want to know why users will be clicking on blank cells though?:)<!--content-->I said that just to make the question simple- becuase in reality, thats all I needed- but take this for example:<br />
<br />
<table border="1" borderColorDark="#000000" borderColorLight="#444444" cellSpacing="0" width="132" height="27"><br />
<tr><br />
<td bgcolor="#444444" style="color: #FFFFFF" onMouseOver="style.color='#FFFFFF'; style.backgroundColor='#992106';" onMouseOut="style.color='#FFFFFF'; style.backgroundColor='#444444';" onClick="window.location.href='http://www.webdeveloper.com/forum/archive/index.php/right.html'" target="main" height="12" width="121"><a href=http://www.webdeveloper.com/forum/archive/index.php/"right.html"><font face="Verdana, Arial, Comic Sans MS" color="#CCCCCC" size="2">Latest<br />
News</font></a></td><br />
</tr><br />
</table><br />
<br />
<br />
<br />
Now, sometimes, there is hardly any text in the box, and it gets annoying trying to click on the small amount of text, rather than just clicking anywhere in the cell (besides, thats just easier ;) )<!--content-->I would leave your regular link in there around your text (pointing to the same place as the onclick) so your pages work for those without javascript...<!--content-->I got the solution! Drum roll....<table border="1"><br />
<tr><br />
<td width="122"><a href=http://www.webdeveloper.com/forum/archive/index.php/"http://www.w3c.org"><div class="yeah">123</div></a></td><br />
</tr><br />
</table><br />
Then put this in a separate stylesheet, or at the top of the file like so:<html><br />
<head><br />
<style><br />
.yeah {width:122px;<br />
background-color:#fce;<br />
cursor:hand;}<br />
</style><br />
</head>What I've done is put the text inside a div and made it as wide as the table cell. Then you can click anywhere in the cell!!<br />
<br />
The background colour is just to test it works. As you can see, the link itself is very small but now it doesn't matter!<br />
<br />
I also had to add "cursor:hand" because IE6 doesn't show the normal cursor for a link otherwise.<br />
<br />
So there you go. And no javascript needed!<!--content-->is that valid?<br />
<br />
7.5.3 of html 4.01 states<br />
<br />
Content model<br />
Generally, block-level elements may contain inline elements and other block-level elements. Generally, inline elements may contain only data and other inline elements. Inherent in this structural distinction is the idea that block elements create "larger" structures than inline elements.<br />
<br />
Is this a general case or not?<br />
Guess Charles will know!<!--content-->Why are we debating what's valid when the guy is using deprecated tags like FONT and inline styles instead of CSS anyway? :) <br />
<br />
Divs can be inline too. Just add "display:inline;". I was going to do it, but it worked without that.<!--content-->oh all right then... LOL<!--content-->Well, isn't this just fine (the text inside ther cell is just a normal hyperlink:) ):<br />
<br />
<table border="1" borderColorDark="#000000" borderColorLight="#444444" cellSpacing="0" width="132" height="27"><br />
<tr><br />
<td bgcolor="#444444" style="color: #FFFFFF" onMouseOver="style.color='#FFFFFF'; style.backgroundColor='#992106';" onMouseOut="style.color='#FFFFFF'; style.backgroundColor='#444444';" onClick="window.location.href='http://www.webdeveloper.com/forum/archive/index.php/right.html'" height="12" width="121"><a href=http://www.webdeveloper.com/forum/archive/index.php/"right.html"><font face="Verdana, Arial, Comic Sans MS" color="#CCCCCC" size="2">Latest<br />
News</font></a></td><br />
</tr><br />
</table><!--content-->I would think that would be ok...<!--content-->Why add an extra div inside the anchor :confused: <br />
CSS:<br />
<br />
td a <br />
{ display: block;<br />
width: 200px;<br />
height: 100px;<br />
/* or whatever the size of the cell is */<br />
}<!--content-->Or this works too:td a<br />
{display: inline;<br />
width: 200px;}<!--content-->
 
Back
Top