Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'div' inside 'table'

Is a div inside a table allowed or not according to W3C?

like image 483
andrew Sullivan Avatar asked Jun 04 '10 13:06

andrew Sullivan


People also ask

Can I use div inside table?

No, you cannot insert a div directly inside of a table.

Can we use div inside TD?

If you use a div in a td you will however get in a situation where it might be hard to predict how the elements will be sized. The default for a div is to determine its width from its parent, and the default for a table cell is to determine its size depending on the size of its content.

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.


2 Answers

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">   <head>     <title>test</title>   </head>   <body>     <table>       <tr>         <td>           <div>content</div>         </td>       </tr>     </table>   </body> </html> 

This document was successfully checked as XHTML 1.0 Transitional!

like image 119
echox Avatar answered Sep 20 '22 16:09

echox


You can't put a div directly inside a table, like this:

<!-- INVALID --> <table>   <div>     Hello World   </div> </table> 

Putting a div inside a td or th element is fine, however:

<!-- VALID --> <table>   <tr>     <td>       <div>         Hello World       </div>     </td>   </tr> </table> 
like image 23
Pär Wieslander Avatar answered Sep 19 '22 16:09

Pär Wieslander