aeq
aeq

Reputation: 10567

Div inside of a <td>?

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 that's floating in the middle of the td.

Upvotes: 0

Views: 366

Answers (5)

Vidar Nordnes
Vidar Nordnes

Reputation: 1364

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

Upvotes: 0

Matti Virkkunen
Matti Virkkunen

Reputation: 65176

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">

Upvotes: 10

NickAldwin
NickAldwin

Reputation: 11754

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.

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382909

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

Upvotes: 1

Brandon Frohbieter
Brandon Frohbieter

Reputation: 18139

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

Upvotes: 0

Related Questions