tags:

views:

67

answers:

3

Hi folks, having an argument with a colleague, but can't find the evidence to prove either of us right!

I have seen the list of valid elements for given tags before, but just cant find it again.

Can anyone point me in the right direction please?

I am curious about XHTML, but the disagreement is specifically over whether a DIV tag is valid within a TD tag in HTML 4.01.

Thanks!

Frosty

+3  A: 

Yes, div within td is perfectly valid. The elements list in the HTML5 spec draft is a useful reference for this sort of question, but basically, the valid children of td are flow elements, and div is a flow element.

The above references are for HTML5, which is the way forward (it both codifies what's already in the wild, and brings things forward; the major browser vendors are all involved). For HTML 4.01, the TD reerence is here, but I have to admit for 4.01 what I'd probably do is ask the W3C validator, which is quite robust for 4.01 (and not yet for HTML5). And the validator says...yup, just fine. Sample data:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
<head><title>Hi</title></head>
<body>
<table><tbody><tr><td><div>x</div></td></tr></tbody></table>
</body>
</html>
T.J. Crowder
HTML 4.01 and not HTML 5.
Gumbo
@Gumbo: I totally missed that, I'll find the HTML 4.01 references, but HTML5 is the way forward in any case.
T.J. Crowder
Updated. Answer is still: Yes, it's fine.
T.J. Crowder
HTML 5 is an unstable draft containing large chunks of stuff that is impractical to use on the web today. It is worth keeping an eye on, but not rushing into. HTML 4.01 is still the best choice for most developers.
David Dorward
@David: Parts of it are certainly unstable (even wildly unstable), but the majority of the *basics* (like which of the old elements can be inside which other old elements) have been reviewed and updated. I wouldn't start using `section` and such yet (not least because it won't work correctly on IE without JavaScript), but for the basics, it's now my default reference point.
T.J. Crowder
+6  A: 

Yes. According to the HTML 4.01 DTD, a td element can contain block-level elements and/or inline-level elements.

Relevent line of the DTD:

<!ELEMENT (TH|TD)  - O (%flow;)*       -- table header cell, table data cell-->

This line basically defines the th and td elements, and states that they may contain any combination (*) of block and inline elements (%flow;).

More info on td: http://www.w3.org/TR/html401/struct/tables.html#edef-TD

cmrn
A: 

Yes you can place a div in a td. I do it all the times.

SiN