HTML
<caption>
element
specifies the caption (or title) of a table.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
| 内容类别 | None. |
|---|---|
| 准许内容 | 流内容 . |
| Tag omission | The end tag can be omitted if the element is not immediately followed by ASCII whitespace or a comment. |
| Permitted parents |
A
<table>
element, as its first descendant.
|
| Implicit ARIA role | 无对应角色 |
| Permitted ARIA roles |
No
role
permitted
|
| DOM 接口 |
HTMLTableCaptionElement
|
此元素包括 全局属性 .
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
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.
<caption>
element should be styled using the
CSS
properties
caption-side
and
text-align
.
<caption>
element should be the first child of its parent
<table>
元素。
当
<table>
element that contains the
<caption>
is the only descendant of a
<figure>
element, you should use the
<figcaption>
element instead of
<caption>
.
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
.
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
caption
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
align
弃用
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持
弃用。不要用于新网站。
<caption>
元素: