Is this code correct?
<table>
<tr>
<td>...</td>
</tr>
<tr>
<div>...</div>
</tr>
<tr>
<td>...</td>
</tr>
</table>
don't know for semantic (and W3C rules). What can you say about?
No, you cannot insert a div directly inside of a table.
<DIV> inside <TD> or <TH> is absolutely fine, and is reasonably common requirement for positioning & layout purposes.
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.
You can't. You'd have to create a new table row and then populate that with a table cell that spans the entire row, then put your DIV in there.
No it is not valid. tr
elements can only contain th
and td
elements. From the HTML4 specification:
<!ELEMENT TR - O (TH|TD)+ -- table row --> <!ATTLIST TR -- table row -- %attrs; -- %coreattrs, %i18n, %events -- %cellhalign; -- horizontal alignment in cells -- %cellvalign; -- vertical alignment in cells -- >
Not only is it not valid, but it doesn't work! This mark-up
<table>
<tr>
<td>The First Row</td>
</tr>
<tr>
<div>The Second Row</div>
</tr>
<tr>
<td>The Third Row</td>
</tr>
</table>
Produces this displayed
The Second Row
The First Row
The Third Row
The div is ejected entirely from the table and placed before it in the DOM
see http://jsfiddle.net/ELzs3/1/
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