tags:

views:

105

answers:

5

Is it valid to have a div inside of a <td> element? I need to display a box inside of the table..

Update:

I need this box (that appears in the td) to have padding..i.e. it really needs to look like a box thats floating in the middle of the td.

A: 

yes, it is valid, but a cell is a box, no?

Orbit
+1  A: 

It is a question of semantic markup, yes you can have a div inside the td.

Sarfraz
A: 

I guess you also could do a <span> inside the <td>

Vidar Nordnes
what is this I don't even
Carson Myers
I assume it was meant to be "I guess you also could do a [HTML ELEMENT] inside the [HTML ELEMENT]" adn that it got stripped... seems harsh from whoever marked him down for a mistake in markup... :)
Chris
sorry about that :P Weird that the editor didn't warn me, or just did a replace of < to < etc...
Vidar Nordnes
A: 

Valid? Perhaps. Good HTML? Maybe not.

Your best option, if you're already (stuck) using tables, is to put another table within the td.

Or you could just create the div inside the td and go on with your day, and not worry about it as long as it works.

NickAldwin
Prima facie, you have no grounds for saying this should be a table or a div - without context you cannot judge what is semantically correct - but the only possible guess you could make is for a div here since "a box" is highly unlikely to be tabular data which would justify a nested table.
annakata
You're right; I was thinking more in terms of the don't-mix-div/span-and-tables style.
NickAldwin
+8  A: 

A div element inside a td element is perfectly valid according to the XHTML 1.0 Strict DTD.

<!ELEMENT td       %Flow;>

<!ENTITY % Flow "(#PCDATA | %block; | form | %inline; | %misc;)*">

<!ENTITY % block
    "p | %heading; | div | %lists; | %blocktext; | fieldset | table">
Matti Virkkunen
Citation of standards deserves +2
annakata