<td> as hyperlink

A

Arjan

Can I make a hyperlink in a <td>-tag???

I want to use it for a forum.


And maybe also a roll-over color in a td-tag?
 
T

Toby A Inkster

Arjan said:
Can I make a hyperlink in a <td>-tag???

You can do:
<td><a href="foobar">Foo Bar</a></td>

Or alternatively, in XHTML 2:
<td href="foobar">Foo Bar</td>

Unfortunately, no browsers support XHTML 2 just yet.
And maybe also a roll-over color in a td-tag?

The proper way would be to do this:

<style type="text/css" media="screen,projection">
td {
color: black;
background-color: white;
}
td:hover {
color: yellow;
background-color: #800;
}
</style>
....
<td>Foo Bar</td>

However, IE won't support this (it works fine in Opera, Netscape and
Mozilla). You can work around it with a little JavaScript though:

<style type="text/css" media="screen,projection">
td {
color: black;
background-color: white;
}
td:hover {
color: yellow;
background-color: #800;
}
</style>
<script type="text/javascript">
function hov(id) {
document.getElementById(id).style.color='yellow';
document.getElementById(id).style.backgroundColor='#800';
}
function hovx(id) {
document.getElementById(id).style.color='black';
document.getElementById(id).style.backgroundColor='white';
}
</script>
....
<td onmouseover="hov('mycell')" onmouseout="hovx('mycell')"
id="mycell">Foo Bar</td>
 
R

Richard

Arjan said:
Can I make a hyperlink in a <td>-tag???
I want to use it for a forum.

And maybe also a roll-over color in a td-tag?

<td><a href="yourtexthere.com">this is a link</a></td>
but not
<a href="yourtexthere.com " <td>stupid idea</td/>>this is not a link</a>
You can not simply embed a tag within a tag.
Naturally, someone will come along and say you can.


<td onmouseover="bgcolor='black'" onmouseout="bgcolor='white'">your text
here</td>
 
T

Toby A Inkster

Richard said:
I don't think that's what he was asking about though.
<td <a href="#">blah</a>>yadayada</td>

No, I think you misinterpreted the question, Richard.
 
R

rf

Richard said:
<td><a href="yourtexthere.com">this is a link</a></td>
but not
<a href="yourtexthere.com " <td>stupid idea</td/>>this is not a link</a>
You can not simply embed a tag within a tag.

Will you PLEASE get your termonology correct, if only for the sake of the
newbies here. The correct term is *element*, not tag.
Naturally, someone will come along and say you can.

You can, unfortunately. The browsers error correction (especially IE's) will
attemp to correct malformed HTML and *sometimes* get it right.

But, after all, what does this have to do with the OP's question? More of
your ramblings I presume...

Cheers
Richard.
 
L

Leif K-Brooks

rf said:
Will you PLEASE get your termonology correct, if only for the sake of the
newbies here. The correct term is *element*, not tag.

He's right calling it a tag this time, even if his idea is insane. He's
talking about embedding the <td> and </td> tags in a <a href="..."> tag,
not putting the <td/> as content for the <a/> element.
 
R

Richard

rf wrote:

Will you PLEASE get your termonology correct, if only for the sake of the
newbies here. The correct term is *element*, not tag.
You can, unfortunately. The browsers error correction (especially IE's)
will attemp to correct malformed HTML and *sometimes* get it right.
But, after all, what does this have to do with the OP's question? More of
your ramblings I presume...
Cheers
Richard.

if you want to get downright technical, in this case, <td> is a tag, but
also an element of <tr> because you can't use <td> without <tr>.
<table> <td>yada</td> <table>
does not work.

<table> <tr><td>yada</td></tr> <table>
does work.
 
S

Steve Pugh

Richard said:
if you want to get downright technical, in this case, <td> is a tag, but
also an element

<td> is a tag.
</td> is a tag.
but also an element of <tr>

because you can't use <td> without <tr>.

That is true, but has nothing to do with whether something is an
element or not.
<table> <td>yada</td> <table>
does not work.

It might work in some browsers, but it's not valid. It has a missing
start tag for the table row element. It also has an improperly nested
table element. Or did you mean that second table tag to be closing
tag?
<table> <tr><td>yada</td></tr> <table>
does work.

It might work in some browsers, but it's still not valid as you've
still got an improperly nested table element.

Did you mean something like this:
<table><tr><td>yada</table>?
Note that the end tags for the table row and table data elements are
optional though a few antique browsers have bugs which cause them to
throw fits if they are omitted.

Steve
 
A

Andrew Cameron

Toby A Inkster said:
No, I think you misinterpreted the question, Richard.

I'd even say on purpose. I'm loathe to get accusatory, but he's either a
troll or the biggest idiot this side of the microsoft.com web development
team.
 
R

rf

Leif K-Brooks said:
He's right calling it a tag this time, even if his idea is insane. He's
talking about embedding the <td> and </td> tags in a <a href="..."> tag,
not putting the <td/> as content for the <a/> element.

No he is not right. The <a> tag is only part of the anchor element. Yes, he
is talking about embedding a table cell element inside the openening tag of
an anchor element but it is both Richards and Arjan's incorrect use of "tag"
that is, as usual, confusing.

If Arjan's original question had been "can I put a hyperlink (anchor
element) inside a table cell element" then the answer would had been
obvious: yes:
<td><a ...>...</a></td>

Using the correct terminology, "element", we simply can not arrive at the
solution Richard supplied. Only when we drop down a level and use "tag"
(which is simply a *part* of an element) can we say "put a table cell inside
a hyperlink tag, to arrive at
<a ...<td>...</td> >...</a> which is of course grossly invalid.

Stay at the, correct, element level and we can only say "put a table cell
element inside an anchor element" to get
<a ...><td>...</td></a> which is not *grossly* invalid, just normally
invalid and nothing at all to do with Arjan's original question.

Another example:
Using the incorrect "tag" we can end up with the classically wrong:
<em>emphasised<strong>emphasised and strong</em>just strong</strong>.

Use the correct "element" terminology and this incorrect nesting can not
occur.

Half the errors that come here for correction (eg the horribly nested table
problem the other day) result from people writing "tags" instead of
"elements". In fact the visual studio .net editor makes very good use of the
"element" concept. Type in an opening tag and the editor auto completes the
element by adding its closing tag. We are now writing HTML as it should be
written, using elements.

Cheers
Richard.
 
S

Steve Pugh

Andrew Cameron said:
I'd even say on purpose. I'm loathe to get accusatory, but he's either a
troll or the biggest idiot this side of the microsoft.com web development
team.

Or both?

Steve
 
R

rf

Richard said:
rf wrote:







if you want to get downright technical,

We can get as technical as you like because I, unlike you I suspect, have
actually read the specifications and have understood them.
in this case, <td> is a tag,
Correct.

but
also an element of <tr>

Incorrect. <td> is not an element of anything. It is the opening *tag* of a
table cell element. The table cell element consists of an opening tag, <td>,
some content (the elements content that is) and a closing tag, </td>.

You can *not* say that this "table cell element" is an element of <tr>,
<tr> is a tag and is only part of a table row element, that is, its opening
tag. You can not even say that this table cell element is an element of a
table row element. What you *can* say is that this table cell element forms
part of the *content* of the table row element.
because you can't use <td> without <tr>.

Incorrect and confusing. The correct statement is "because you may not use a
table cell element without enclosing it within a table row element, so it
forms part of the *content* of the table row element. It is your continual
use of the incorrect term "tag" rather than the correct term "element" that
is causing you all this trouble.
<table> <td>yada</td> <table>
does not work.

Define "work". The above "works" quite admirably in IE because if a browser
is presented with *invalid* HTML it is up to the browser to interpret what
the result should be. IE goes a bit overboard in its error correction
sometimes but it *does* get this one right.

Get a little more complex, like
<table> <td>yada</td> <td>yada</td> <table>
and yes, things start to fall apart but this still "works", in that the
content is presented on the canvas. There may be only one "cell" instead of
two but that is only eye candy anyway.

I think you actully meant "is invalid as per the specifications" rather than
"does not work".

Cheers
Richard.
 
L

Leif K-Brooks

rf said:
Using the correct terminology, "element", we simply can not arrive at the
solution Richard supplied. Only when we drop down a level and use "tag"
(which is simply a *part* of an element) can we say "put a table cell inside
a hyperlink tag, to arrive at
<a ...<td>...</td> >...</a> which is of course grossly invalid.

Yes, but that's what he was talking about doing. It's stupid and
invalid, but it was what he was talking about.
 
R

rf

Leif K-Brooks said:
Yes, but that's what he was talking about doing. It's stupid and
invalid, but it was what he was talking about.

Exactly, Leif. I agree with you here. My point is simply that, if that
Richard were to use the *correct* terminology then he would not be *able* to
talk about the stupidly invalid stuff he sprouts. "Element within element"
implies <a><td></td></a>. It cannot imply <a <td></td>></a> because that is
*not* element within element. It is, to use the incorrect terminology,
element within tag.

Use the correct terminology and half the battle is over.

Cheers
Richard.
 

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

Members online

Forum statistics

Threads
473,815
Messages
2,569,703
Members
45,494
Latest member
KandyFrank

Latest Threads

Top