【发布时间】:2013-11-07 17:10:05
【问题描述】:
假设我有给定的表:
+------+------+------+
| Col1 | Col2 | Col3 |
+------+------+------+------+
| Row1 | D1.1 | D1.2 | D1.3 |
+------+------+------+------+
| Row2 | D2.1 | D2.2 | D2.3 |
+------+------+------+------+
| Row3 | D3.1 | D3.2 | D3.3 |
+------+------+------+------+
我想用 HTML5 来表示它。棘手的是,像这样的表格必须在语义上很重要,但左上角的单元格在语义上不很重要,而是一个分隔符来排列更重要的列标题。最好的方法是什么?我的第一个想法是这样做:
<table>
<thead>
<tr>
<th></th>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</tr>
</thead>
<tbody>
<tr>
<th>Row1</th>
<td>D1.1</td>
<td>D1.2</td>
<td>D1.3</td>
</tr>
<tr>
<th>Row2</th>
<td>D2.1</td>
<td>D2.2</td>
<td>D2.3</td>
</tr>
<tr>
<th>Row3</th>
<td>D3.1</td>
<td>D3.2</td>
<td>D3.3</td>
</tr>
</tbody>
</table>
不过,将<th></th> 放在那里感觉是错误的,就像使用<p>&nbsp;</p> 作为间距一样。 有更好的方法吗?
【问题讨论】:
-
空元素没有问题。 There is even an
:emptyselector. -
@JoshC 有趣...你能详细说明一下答案吗?
-
我认为值得一提的是,在过去的 7 年中,我开始看到像这样的空元素在语义上很重要,因为它们在语义上表示“这里没有数据”。这对于解析器来说非常重要,这也是语义 HTML 背后的意图
标签: html html-table semantic-markup