验证(HTML5):元素'th'不能嵌套在元素'table'中

Coo*_*ops 8 html5 html-validation

鉴于以下HTML,为什么会出现错误:

验证(HTML5):元素'th'不能嵌套在元素'table'中

<table>
    <th>ID</th>
    <th>text header</th>
    <tr>
        <td>7</td>
        <td>text</td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

Coo*_*ops 23

您不能将<th>元素<tr>置于a之外,以下代码段有效

<table>
    <tr>
        <th>ID</th>
        <th>text header</th>
    </tr>
    <tr>
        <td>7</td>
        <td>text</td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

<th>使用上下文 https://developer.mozilla.org/en/docs/Web/HTML/Element/th

允许的父元素

一个<tr>元素.