HTML W3C Valid Elements - Is DIV valid within a TD?
I'm having an argument with a colleague, but can't find开发者_JS百科 the evidence to prove either of us right. I've 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.
Yes. According to the HTML 4.01 DTD, a td
element can contain block-level elements and/or inline-level elements.
Relevant 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
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">
<html>
<head><title>Hi</title></head>
<body>
<table><tbody><tr><td><div>x</div></td></tr></tbody></table>
</body>
</html>
Yes you can place a div in a td. I do it all the times.
精彩评论