开发者

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>data开发者_StackOverflow中文版1-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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜