I'm having an argument with a colleague, but can't find 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.
One important thing to remember when putting a div inside of a table is that the div needs to live inside of a particular table cell, meaning inside of a td or th element which is inside of a tr element. This can help with using absolute positioning inside of table cells as well.
You can put div tags inside a td tag, but not directly inside a table or tr tag.
With HTML, you can easily add HTML tag inside a table. The tag should open and close inside the <td> tag. For example, adding a paragraph <p>…
What are the Tdap and Td vaccines? Tdap and Td are shots given to protect your child from tetanus, diphtheria, and pertussis (whooping cough). These are severe infections caused by bacteria.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With