HTML5 是否禁止 tbody 中的单元格?
我将以下标记作为 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>
将“验证的目标架构”设置为 HTML5 时,Visual Studio 会这样抱怨:
警告 1 验证 (HTML5):元素“th”不得嵌套在元素“tbody tfoot”内。
这是真的吗?如果是这样,有人可以链接到该规范吗?
我的理解是,使用 作为行标题不仅合法,而且受到鼓励。这看起来确实很常见,我可以链接数十个教程(看起来很明智)解释它有助于提高可访问性。
这是VS的bug吗? HTML5 带来了真正的变化(好的变化?坏的变化?)?这是什么故事?
I have the following markup as a part of a Razor view:
<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>
With the "target schema for validation" set to HTML5, Visual Studio complains thusly:
Warning 1 Validation (HTML5): Element 'th' must not be nested within element 'tbody tfoot'.
Is this really true? If so, could someone link to the spec?
My understanding was that using <th>
for row headers was not just legal but encouraged. It certainly seems fairly common, I could link dozens of tutorials explaining (seemingly sensibly) that it helps with accessibility.
Is this a VS bug? A real change coming with HTML5 (a good one? a bad one?)? What's the story?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,这在 HTML 4(可能还有其前身)中始终是合法的,并且没有改变在 HTML5 中。
W3C 的 HTML5 验证器虽然仍处于实验阶段,但没有报告任何警告或错误。话又说回来,我确信 Visual Studio 使用的 HTML5 验证也是实验性的,因为 HTML5 本身尚未最终确定。
关于标记表格数据的 HTML5 规范,特别是 第 4.9.13 节,显示了使用
和
中的
来限定行数据范围:
因此,使用
< 是完全合法的
元素。无论如何,表格标题应该如此,因为表格标题不仅仅出现在表格标题上。或
内的
元素内的 ;th>
As far as I know, this was always legal in HTML 4 (and possibly its predecessors), and hasn't changed in HTML5.
W3C's HTML5 validator, while still experimental, reports no warnings or errors. Then again, I'm sure the HTML5 validation Visual Studio is using is experimental as well since HTML5 itself hasn't yet been finalized.
The HTML5 spec on marking up tabular data, specifically section 4.9.13, shows the use of
<th>
within<tbody>
and<tfoot>
to scope row data:So it's perfectly legitimate to have
<th>
elements inside<tr>
elements inside either a<tbody>
or<tfoot>
. As it should be anyway, since table headings aren't just found on table headers.HTML5 规范 仅需要它位于
tr
内,并且规范实际上包含一个th
嵌套在tbody
内的示例。The HTML5 spec only requires that it be inside a
tr
, and the spec actually includes an example with ath
nested inside atbody
.通常,
THEAD
中的TH
的scope
值为"col"
,而TH<
TBODY
中的 /code> 的scope
值为“row”
。Generally a
TH
in aTHEAD
will have ascope
value of"col"
while aTH
in aTBODY
will have ascope
value of"row"
.