Can a td be inside a td

2020-06-07 07:28发布

问题:

It may be a nonsense question, and I know we have to follow standards as much as possible. But can <td> be a direct child of another <td>, like this:

<td class="parent">
    <td class="child">
        <!-- Some info -->
    </td>
</td>

Or it's obligatory to create another <table> with a new <tr> before adding the <td>, which can become heavily populated with table tags and become clustered...

回答1:

not directly but you could place table inside td

<td class="parent">
   <table><tr>
    <td class="child">
        <!-- Some info -->
    </td>
   </tr></table>
</td>


回答2:

No, <td> may not be a child of a <td>. A <td> may only be a child of a <tr>.



回答3:

it's better to create a new table tag.

The example you give is not standard and the behavior can be different from a browser to another one



回答4:

The problem with not following standards like putting a <td> tag inside a <dt>, is that you cannot guarantee that the result is the same for all browsers, or that the next update of any browser will for example not simply ignore wrongly-used tags.

As a sidenote: we, as a developer comunity, have cried and shouted for Internet Explorer to finally start to take the standards seriously, so now let's not start making a mess ourselves!