HTML <caption> 标签

html <caption> 标签用于定义表格的标题

<caption> 标签必须直接放置到 <table> 标签之后

只能对每个表格定义一个标题

通常这个标题会被居中于表格之上,不过可以通过 css 属性 "text-align" 和 "caption-side" 能用来设置标题的对齐方式和显示位置

属性

属性 描述
align
left
right
top
bottom
html5 不支持
HTML 4.01 已废弃
定义标题的对齐方式


范例

带有标题的表格

<table border="1">
  <caption>Monthly savings</caption>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>

HTML 4.01 与 HTML5 之间的差异

HTML5 不支持 align 属性

HTML 4.01 已废弃 align 属性