What is the purpose for HTML's tbody?

前端 未结 6 377
情话喂你
情话喂你 2020-12-02 22:44

What are the main reasons someone would use HTML\'s tbody in a table? Is it just for formatting purposes?

I use head and body

6条回答
  •  醉梦人生
    2020-12-02 23:25

    To give semantic meaning to your table:

    Person Amount Date
    Person1 $5.99 02/03/09
    Person2 $12.99 08/15/09

    According to the 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.

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

    When present, each THEAD, TFOOT, and TBODY contains a row group. Each row group must contain at least one row, defined by the TR element.

    Besides the important semantic importance of this (think screen readers), you can then easily style your headers apart from your data rows. Another relevant example is jQuery plugins such as the Tablesorter (original, archived) plugin can then easily figure out what your data structure looks like.

提交回复
热议问题