【问题标题】:Are table headers only for the top row in html?表格标题是否仅适用于 html 中的第一行?
【发布时间】:2016-11-27 00:32:59
【问题描述】:

我总是看到 th 标签只用在表格的第一行。是否有某些特定原因不能用于沿最左侧的列创建“左侧”标题。这是不好的形式,还是可以。

基本上,表格的第一行和最左列都有标题,最左上角的方块是空的。

例如

<table>
    <tr>
        <th><!--empty--></th>
        <th>Top 1</th>
        <th>Top 2</th></tr>
    <tr>
        <th>LeftHeader?</th>
        <td>data1</td>    
        <td>data2</td></tr>
</table>

【问题讨论】:

  • 不,那是完全合法的。
  • 自动关闭非空元素,例如&lt;tr/&gt; 无效。使用验证器并自己进行测试。

标签: html html-table


【解决方案1】:

这是有效的,但是,当使用&lt;thead&gt; 时,它必须是第一行。这是有效的:

<table>
    <thead>
        <tr>
            <td>0,0</td><td>1,0</td><td>2,0</td>
        </tr>
    </thead>
    <tr>
        <th>0,1</th><th>1,1</th><th>2,1</th>
    </tr>
</table>

但这不是:

<table>
    <tr>
        <td>0,0</td><td>1,0</td><td>2,0</td>
    </tr>
    <thead>
        <tr>
            <th>0,1</th><th>1,1</th><th>2,1</th>
        </tr>
    </thead>
</table>

这是无效的 HTML,您可以使用 the w3C markup validation service 仔细检查,但在此之前您必须添加 &lt;!DOCTYPE&gt; 声明和有效 HTML 文档的其余部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    • 2016-11-05
    • 2018-06-26
    相关资源
    最近更新 更多