<caption> 标签用于定义 <table> 元素的标题。通常情况下,<caption> 标签应该紧随在 <table> 标签之后,并且在 <table> 内部的第一个元素。
在一个表格中只能有一个 <caption> 标签,用于描述表格的内容或提供表格的标题。
语法
// www.javascriptcn.com code example
<table>
<caption>这是表格标题</caption>
<tr>
<th>表头1</th>
<th>表头2</th>
</tr>
<tr>
<td>数据1</td>
<td>数据2</td>
</tr>
</table>属性
- align: 指定
<caption>元素的对齐方式,可选值包括top,bottom,left,right。默认为top。
示例
// www.javascriptcn.com code example
<table>
<caption align="bottom">这是表格标题</caption>
<tr>
<th>姓名</th>
<th>年龄</th>
</tr>
<tr>
<td>小明</td>
<td>25</td>
</tr>
</table>在上面的示例中,<caption> 标签用于显示表格的标题,并且使用 align="bottom" 属性将标题置于表格底部。
<caption> 标签的使用可以使表格更具可读性,帮助用户更好地理解表格内容。