I didn't think this was a problem but my IDE seems to tell me otherwise. Are there any browsers that would fail to render this correctly?
Using Netbeans IDE 7.3.
Thanks.
Nothing is wrong with placing a div inside a tag. In fact, you can place just about anything inside a tag as long as they are categorized as transparent , except that no descendant may be interactive content (eg: buttons or inputs) or an a element, and no descendant may have a specified tabindex attribute.
No, you cannot insert a div directly inside of a table.
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.
According to the HTML5 specification, that's absolutely fine. The content model is a normative description of what is allowed to be a child/descendant of the element. For the <th>
element, only the following tags are permitted:
Content model:
Flow content, but with no header, footer, sectioning content, or heading content descendants, and if the th element is a sorting interface th element, no interactive content descendants.
The <div>
tag is an example of flow content, so this should validate.
In the future, I'd like to recommend the W3C's validator service, which gives you a quick check to see whether your HTML is valid. In this instance, it passes:
<!DOCTYPE html>
<html>
<head><title> </title></head>
<body>
<table>
<tbody>
<tr>
<th>
<div></div>
</th>
</tr>
</tbody>
</table>
</body>
</html>
<DIV>
inside <TD>
or <TH>
is absolutely fine, and is reasonably common requirement for positioning & layout purposes.
For example, the TH
cannot have position:relative
set, but the DIV
can.. enabling it to be a positioning container.
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