HTML5是否禁止tbody?

Dou*_*ean 48 html asp.net-mvc html5 web-standards

我有以下标记作为Razor视图的一部分:

<table>
  <caption>Presidents</caption>
  <thead>
    <tr>
      <th scope="col">Name</th>
      <th scope="col">Born</th>
      <th scope="col">Died</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Washington</th>
      <td>1732</td>
      <td>1799</td>
    </tr>
    <!-- etc -->
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

将"验证的目标模式"设置为HTML5,Visual Studio就这样抱怨:

警告1验证(HTML5):元素'th'不得嵌套在元素'tbody tfoot'中.

这是真的吗?如果是这样,有人可以链接到规范吗?

我的理解是,使用<th>行标题不仅是合法的,而且是鼓励的.这当然看起来相当普遍,我可以链接几十个教程解释(看似合情合理)它有助于可访问性.

这是VS的错误吗?HTML5真正的变化(一个好的?一个坏的?)?发生了什么?

Bol*_*ock 61

我的理解是,使用<th>行标题不仅是合法的,而且是鼓励的

据我所知,这在HTML 4(可能还有它的前身)中总是合法的,并且在HTML5中没有改变.

W3C的HTML5验证器虽然仍然是实验性的,但没有报告任何警告或错误.然后,我确信Visual Studio正在使用的HTML5验证也是实验性的,因为HTML5本身尚未最终确定.

标记表格数据的HTML5规范,特别是第4.9.13节,显示了行数据的使用<th>范围<tbody><tfoot>范围:

<table>
 <thead>
  <tr>
   <th>
   <th>2008
   <th>2007
   <th>2006
 <tbody>
  <tr>
   <th>Net sales
   <td>$ 32,479
   <td>$ 24,006
   <td>$ 19,315
  <tr>
   <th>Cost of sales
   <td>  21,334
   <td>  15,852
   <td>  13,717
 <tbody>
  <tr>
   <th>Gross margin
   <td>$ 11,145
   <td>$  8,154
   <td>$  5,598
 <tfoot>
  <tr>
   <th>Gross margin percentage
   <td>34.3%
   <td>34.0%
   <td>29.0%
</table>
Run Code Online (Sandbox Code Playgroud)

因此,将<th>元素内部<tr>元素放在a <tbody>或中是完全合理的<tfoot>.无论如何应该是这样,因为表标题不只是在表头上找到.

  • 我同意.我创建了[问题656626](http://connect.microsoft.com/VisualStudio/feedback/details/656626/html5-validation-reports-spurious-error-when-th-tags-appear-within-tbody-tags)报告这个. (21认同)
  • 我可以通过更改`html_5.xsd`和`xhtml_5.xsd`来修复VS2010上的警告,基于Chris的[回答](http://stackoverflow.com/questions/9603241/html5-element-legend-occurs-too -few倍#答案-12912876).打开文件,找到行`<xsd:element ref ="th"vs:disallowedancestor ="tbody tfoot"/>`并将其更改为`<xsd:element ref ="th"/>`. (3认同)

Chu*_*uck 11

HTML5规范只要求它在一个内部tr,而规范实际上包含一个th嵌套在一个内部的例子tbody.


Chr*_*rth 5

一般来说,aTH中的 a的值为THEAD,而 a中的 a的值为。scope"col"THTBODYscope"row"