<caption>: The Table Caption element - HTML: HyperText Markup Language 编辑

The HTML <caption> element specifies the caption (or title) of a table.

Content categoriesNone.
Permitted contentFlow content.
Tag omissionThe end tag can be omitted if the element is not immediately followed by ASCII whitespace or a comment.
Permitted parentsA <table> element, as its first descendant.
Implicit ARIA roleNo corresponding role
Permitted ARIA rolesNo role permitted
DOM interfaceHTMLTableCaptionElement

Attributes

This element includes the global attributes.

Deprecated attributes

The following attributes are deprecated and should not be used. They are documented below for reference when updating existing code and for historical interest only.

align This deprecated API should no longer be used, but will probably still work.
This enumerated attribute indicates how the caption must be aligned with respect to the table. It may have one of the following values:
left
The caption is displayed to the left of the table.
top
The caption is displayed above the table.
right
The caption is displayed to the right of the table.
bottom
The caption is displayed below the table.
Usage note: Do not use this attribute, as it has been deprecated. The <caption> element should be styled using the CSS properties caption-side and text-align.

Usage notes

The <caption> element should be the first child of its parent <table> element.

When the <table> element that contains the <caption> is the only descendant of a <figure> element, you should use the <figcaption> element instead of <caption>.

Example

This simple example presents a table that includes a caption.

<table>
  <caption>Example Caption</caption>
  <tr>
    <th>Login</th>
    <th>Email</th>
  </tr>
  <tr>
    <td>user1</td>
    <td>user1@sample.com</td>
  </tr>
  <tr>
    <td>user2</td>
    <td>user2@sample.com</td>
  </tr>
</table>
caption {
  caption-side: top;
  align: right;
}
table {
  border-collapse: collapse;
  border-spacing: 0px;
}
table, th, td {
  border: 1px solid black;
}

table {background: red;} do not alter caption. For that you need display: block.

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of '<caption>' in that specification.
Living Standard
HTML5
The definition of '<caption>' in that specification.
Recommendation
HTML 4.01 Specification
The definition of '<caption>' in that specification.
Recommendation

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:77 次

字数:7807

最后编辑:6年前

编辑次数:0 次

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