为什么内部 TABLE 部分必须经过 THEAD TFOOT TBODY 才能验证?

发布于 2024-10-31 07:12:56 字数 1876 浏览 1 评论 0原文

我经常使用 THEAD、TBODY 和 TFOOT 元素将数据表划分为可以使用 CSS 单独寻址的部分。我也明白总是有一个隐式的 TBODY 标签。

让我困惑的是这些必须进入验证的顺序。此表将验证:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Table Validation Test</title>
</head>
<body>

<table>

<thead>
<tr>
    <th scope="col">Enemies List</th>
</tr>
</thead>

<tfoot>
<tr>
    <td>&copy; Bomb Voyage</td>
</tr>
</tfoot>

<tbody>
<tr>
    <td>Mr. Incredible</td>
    <td>Elastigirl</td>
    <td>Gazer Beam</td>
</tr>
</tbody>

</table>
</body>
</html>

但此表​​不会:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Table Validation Test</title>
</head>
<body>

<table>

<thead>
<tr>
    <th scope="col">Enemies List</th>
</tr>
</thead>

<tbody>
<tr>
    <td>Mr. Incredible</td>
    <td>Elastigirl</td>
    <td>Gazer Beam</td>
</tr>
</tbody>


<tfoot>
<tr>
    <td>&copy; Bomb Voyage</td>
</tr>
</tfoot>

</table>
</body>
</html>

有效的表为 HEAD、FOOT、BODY;这没有任何意义。

将脚放在桌子底部可以保持桌子与人体之间的类比。但由于某种原因,这个命令被认为是无效的。

有人知道为什么吗?

I often use THEAD, TBODY, and TFOOT elements to divide my data tables into sections that can be addressed separately with CSS. I also understand that there is always an implicit TBODY tag.

What puzzles me is the order that these have to go in to validate. THIS table will validate:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Table Validation Test</title>
</head>
<body>

<table>

<thead>
<tr>
    <th scope="col">Enemies List</th>
</tr>
</thead>

<tfoot>
<tr>
    <td>© Bomb Voyage</td>
</tr>
</tfoot>

<tbody>
<tr>
    <td>Mr. Incredible</td>
    <td>Elastigirl</td>
    <td>Gazer Beam</td>
</tr>
</tbody>

</table>
</body>
</html>

But this one will not:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Table Validation Test</title>
</head>
<body>

<table>

<thead>
<tr>
    <th scope="col">Enemies List</th>
</tr>
</thead>

<tbody>
<tr>
    <td>Mr. Incredible</td>
    <td>Elastigirl</td>
    <td>Gazer Beam</td>
</tr>
</tbody>


<tfoot>
<tr>
    <td>© Bomb Voyage</td>
</tr>
</tfoot>

</table>
</body>
</html>

The valid one goes HEAD, FOOT, BODY; which does not make any sense.

Putting the foot at the bottom of the table would maintain the analogy between the table and a human body. But for some reason, this order is considered invalid.

Anyone know why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情场扛把子 2024-11-07 07:12:56

规范给出了一个原因:

TFOOT 必须出现在 TABLE 定义中的 TBODY 之前,以便用户代理可以在接收所有(可能有很多)数据行之前呈现脚部。

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

我不知道是否有浏览器实际上遵循这种行为,并且在 HTML5 中对其进行了更改以处理 HTML 4 顺序和更逻辑的顺序:

按此顺序:可选的一个 title 元素,后跟零个或多个 colgroup 元素,可选地后跟一个 thead 元素,后跟可选的 tfoot 元素,后跟零个或多个 tbody 元素或一个或多个 tr 元素,最后跟随可选地通过 tfoot 元素(但总共只能有一个 tfoot 子元素)。

http://www.w3.org/TR/html5/tabular-data.html

The spec provides a reason:

TFOOT must appear before TBODY within a TABLE definition so that user agents can render the foot before receiving all of the (potentially numerous) rows of data.

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

I don't know if any browsers actually follow this behavior, and it was changed in HTML5 to handle both the HTML 4 order and the more logical order:

In this order: optionally a caption element, followed by zero or more colgroup elements, followed optionally by a thead element, followed optionally by a tfoot element, followed by either zero or more tbody elements or one or more tr elements, followed optionally by a tfoot element (but there can only be one tfoot element child in total).

http://www.w3.org/TR/html5/tabular-data.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文