What is benefit of

2020-08-09 07:57发布

What is benefit of using thead instead of just td? If there is benefit...

标签: html
10条回答
迷人小祖宗
2楼-- · 2020-08-09 08:16

thead is not used very often. It identifies a section of a table that is the "header" and is sort of a hint to the browser that the user might want to see this piece, even if he scrolls the rest of the table up and down. http://www.w3schools.com/tags/tag_thead.asp

查看更多
男人必须洒脱
3楼-- · 2020-08-09 08:17

Here is one advantage I found. Say you want to print a web-page that has so much rows that the whole table fits in more than one page (when you want it to be printed). thead will actually cause the browser to include the table header in all the pages(to which the table extends) and hence improve readability. You can read it here

查看更多
Animai°情兽
4楼-- · 2020-08-09 08:26

From the w3c specification:

Table rows may be grouped into a table head, table foot, and one or more table body sections, using the THEAD, TFOOT and TBODY elements, respectively. This division enables user agents to support scrolling of table bodies independently of the table head and foot. When long tables are printed, the table head and foot information may be repeated on each page that contains table data.

Hope this helps.

查看更多
贪生不怕死
5楼-- · 2020-08-09 08:28

I don't see it mentioned here yet, but another benefit is that in most browsers you can actually code <thead>, <tfoot>, and <tbody> out of order and they will appear in the right place on the table. While obscure, I have taken advantage of this before. For example:

<?php $count = 0; ?>
<table>
  <tbody>
    <?php foreach($foo as $f):?>
      <tr>...</tr>
      <?php $count++; ?>
    <?php endforeach; ?>
  </tbody>
  <thead>
    <th>Entries (<?=$count?> total)</th>
    ...
  </thead>
</table>

I wanted a total number of rows listed in the header, so I incremented a counter in my foreach() and put the <thead> at the bottom, so that I could use the value of $count in my header.

Certainly not the main benefit, but a benefit nonetheless.

查看更多
登录 后发表回答