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:06

THEAD is intended to wrap all header rows. Its counterparts are TBODY and TFOOT. They are useful if you want to differentiate those rows via CSS or JavaScript.

查看更多
beautiful°
3楼-- · 2020-08-09 08:14

Using thead, tfoot and tbody let you apply special formatting to the respective parts of the table. For instance, you can include the header and the footer on all the printed pages of your table, or you can make the tbody scroll while the thead & tfoot would remain static.

查看更多
我只想做你的唯一
4楼-- · 2020-08-09 08:15

The thead, tbody, and tfoot elements in HTML are used to group table rows into logical sections based on their content. There are two main reasons you'd want to do this:

  1. To allow the body to be scrolled independently of the header and/or footer

  2. To make it easier to apply different style rules to the different sections of the table.

查看更多
可以哭但决不认输i
5楼-- · 2020-08-09 08:16

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.

The table head and table foot should contain information about the table's columns. The table body should contain rows of table data.

http://www.w3.org/TR/html401/struct/tables.html#h-11.2.3

查看更多
冷血范
6楼-- · 2020-08-09 08:16

The thead and td are in no way comparable. The thead just represents a table header and the td a table cell.

<table>
    <thead>
        <tr><th>head1</th><th>head2</th></tr>
    </thead>
    <tbody>
        <tr><td>row1col1</td><td>row1col2</td></tr>
        <tr><td>row2col1</td><td>row2col2</td></tr>
    </tbody>
</table>

Also see the w3schools tutorial.

A semantic benefit is that you separate the table header from the table body (and if any, also the table footer which can be represented by <tfoot>). The technical benefit is that you can style them separately and for example easily achieve a table with a scrollable body with a fixed header/footer by just giving the <tbody> a fixed height and an overflow. Unfortunately MSIE is the only browser which doesn't support it.

查看更多
Viruses.
7楼-- · 2020-08-09 08:16

<thead> <tbody> and <tfoot> mark specific sections of the table (you put rows inside of them) as being the header, body and footer of the table. This can be used to repeat headers and footers on each table (some browsers do it by default, others seem to need help). See Repeat table headers in print mode

查看更多
登录 后发表回答