简体   繁体   中英

HTML tbody and thead in rotated table

In HTML we can use <tbody> and <thead> .

Which works fine with a 'normal' table.

<table>
  <thead>
    <tr>
      <th>col1</th>
      <th>col2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>data1-1</td>
      <td>data1-2</td>
    </tr>
  </tbody>
</table>

However sometimes there is a rotated table:

<table>
  <tr>
    <th>col1</th>
    <td>data1-1</td>
  </tr>
  <tr>
    <th>col2</th>
    <td>data1-2</td>
  </tr>
</table>

When I use a rotated table I never use <tbody> or <tbody> .

However if I'm correct the <tbody> is mandatory if a <tfoot> is used.

Does a <tr> have to be inside a <tbody>

So my question is:

Is the above statement correct (that it is indeed mandatory if a <tfoot> is used)?

If so where would you add <thead> s and <tbody> s in the second example table?

According to the W3 specification the tbody tag is always mandatory unless your table has only one table body and there is no header and foot sections.

In your case you can use:

<table>
  <tbody>
   <tr>
    <td>col1</td>
    <td>data1-1</td>
   </tr>
   <tr>
    <td>col2</td>
    <td>data1-2</td>
   </tr>
  </tbody>
 </table>

That is HTML valid. Since you don't have "real" header on top of the table I think no header tag applies here. I'm not sure rotated tables are supported by HTML convention, so you basically have a normal table with only body.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM