【问题标题】:Tables thead , tbody and tfoot表格thead , tbody 和tfoot
【发布时间】:2019-04-06 04:41:18
【问题描述】:

如果我有一个带有标题和表格行的表格,我是否需要使用 thead、tbody 和 tfoot 标签? 也可以在 td 上上课还是使用 span 更好? 以下是我的做法,但我有一些疑问。

        <table class="table-myTable">
        <caption>Courseware Production Status</caption>
                <tr>
                    <th>A</th>
                    <th>B</th>
                    <th>C</th>
                </tr>
                <tr>
                    <td>1</td>
                    <td>2</td>
                    <td class="myClass">3</td>
                </tr>
       </table>

【问题讨论】:

    标签: html html-table


    【解决方案1】:

    You have the right to not use &lt;thead&gt;, &lt;tbody&gt;, or &lt;tfoot&gt;. 如果您选择不使用&lt;tbody&gt; 作为您的&lt;tr&gt;s,one will be created for them by the browser engine。证明:

    td:before {
      content: 'bare td';
    }
    
    tbody td:before {
      content: 'inside a tbody';
    }
    <table>
      <tr>
        <td></td>
      </tr>
    </table>

    您可以将类与任何元素一起使用。如果该类适用于整个单元格,请将其放在&lt;td&gt; 上。如果它特别适用于单元格内的文本,请使用&lt;span&gt;,或者最好使用多个semantic elements 之一。

    【讨论】: