Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML W3C Valid Elements - Is DIV valid within a TD?

Tags:

html

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.

like image 848
FrostbiteXIII Avatar asked Jun 25 '10 11:06

FrostbiteXIII


People also ask

Is div allowed inside TD?

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.

Can div be a child of TD?

You can put div tags inside a td tag, but not directly inside a table or tr tag.

What tags can be used inside TD?

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 can be a child of TD?

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.


2 Answers

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

like image 147
cmrn Avatar answered Sep 24 '22 13:09

cmrn


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>
like image 43
T.J. Crowder Avatar answered Sep 25 '22 13:09

T.J. Crowder