<thead> 标签定义 HTML 表格的表头部分。表头部分通常包含表格的列标题。
语法
// www.javascriptcn.com code example
<table>
<thead>
<tr>
<th>列1</th>
<th>列2</th>
<th>列3</th>
</tr>
</thead>
<tbody>
<tr>
<td>数据1</td>
<td>数据2</td>
<td>数据3</td>
</tr>
</tbody>
</table>属性
align: 定义表头内容的对齐方式,可选值有left,center,right,justify,char。valign: 定义表头内容的垂直对齐方式,可选值有top,middle,bottom,baseline。
示例
// www.javascriptcn.com code example
<table border="1">
<thead>
<tr>
<th align="left">姓名</th>
<th align="center">年龄</th>
<th align="right">性别</th>
</tr>
</thead>
<tbody>
<tr>
<td>张三</td>
<td>25</td>
<td>男</td>
</tr>
<tr>
<td>李四</td>
<td>30</td>
<td>女</td>
</tr>
</tbody>
</table>在上面的示例中,<thead> 标签包含了一个表头行,每个表头单元格使用 <th> 标签表示列标题。可以使用 align 和 valign 属性来设置表头内容的对齐方式。
这样,当浏览器渲染表格时,表头部分会以不同的样式显示,使得用户更容易理解表格的结构和内容。
| 属性 | 值 | 描述 |
|---|---|---|
| align | right left center justify char | HTML5 不支持。定义 <thead> 元素中内容的对齐方式。 |
| char | character | HTML5 不支持。规定 <thead> 元素中内容根据哪个字符来对进行文本对齐。 |
| charoff | number | HTML5 不支持。规定 <thead> 元素中内容的第一个对齐字符的偏移量。 |
| valign | top middle bottom baseline | HTML5 不支持。规定 <thead> 元素中内容的垂直对齐方式。 |