组织表格的正确方法
我有这个标记
<div id="standards">
<table border="1">
<thead>
<tr>
<th>Markup</th>
<th colspan="4">HTML</th>
<th colspan="4">XHTML</th>
</tr>
</thead>
<tbody>
<tr>
<th>Version</th>
<td colspan="3">4.01</td>
<td>5</td>
<td colspan="3">1.0</td>
<td>5</td>
</tr>
<tr>
<th>Flavour</th>
<td>Strict</td>
<td>Transitional</td>
<td>Frameset</td>
<td>N/A</td>
<td>Strict</td>
<td>Transitional</td>
<td>Frameset</td>
<td>N/A</td>
</tr>
<tr>
<th>Support</th>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</tbody>
我的问题是我应该将第一个和第二个“tr”保留在“tbody”中,还是现在从语义的角度将它们移动到“thead”。可以看到,该表有 3 个标题。这样做的正确方法是什么?这是小提琴
I have this markup
<div id="standards">
<table border="1">
<thead>
<tr>
<th>Markup</th>
<th colspan="4">HTML</th>
<th colspan="4">XHTML</th>
</tr>
</thead>
<tbody>
<tr>
<th>Version</th>
<td colspan="3">4.01</td>
<td>5</td>
<td colspan="3">1.0</td>
<td>5</td>
</tr>
<tr>
<th>Flavour</th>
<td>Strict</td>
<td>Transitional</td>
<td>Frameset</td>
<td>N/A</td>
<td>Strict</td>
<td>Transitional</td>
<td>Frameset</td>
<td>N/A</td>
</tr>
<tr>
<th>Support</th>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</tbody>
My question is should I leave the first and second "tr" in the "tbody" as it is now, or should I move them to "thead" from the point of view of semantics. The table as can be seen, has 3 headers. What would be the correct way of doing this? Here is the fiddle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 HTML4 和 HTML5 这样做会在语义方面适合您的表格,因此请继续将它们移至标题。
You can have multiple
<tr>
's in<thead>
according to the w3 documentation for HTML4 and HTML5 and doing that would fit your table in terms of semantics, so go ahead and move them to the thead.如果该表确实有 3 行标题(不是数据),请将它们放入
中。
一般用于实际数据。
表格行中的
没有任何问题,它表示该单元格是该特定行的标题。
你就这样就好了。
If this table really has 3 rows of headers (not data), put them in
<thead>
.<td>
is for actual data in general.There's nothing wrong with
<th>
in a table row, it indicates that the cell is header for that particular row.You're fine the way it is.