HTML 表格表头单元格
2025-04-24
17
参考资料
HTML 表格表头单元格格式化
详细介绍
HTML表格表头单元格(<th>
)用于定义表格中的标题单元格,通常位于第一行或第一列,与普通数据单元格(<td>
)区分开来。
标签
<th>表头内容</th>
用法
必须包含在
<tr>
标签内可以包含
colspan
和rowspan
属性来合并单元格可以使用
scope
属性指定关联范围(col
/row
/colgroup
/rowgroup
)
实例
<table> <tr> <th>姓名</th> <th>年龄</th> <th>城市</th> </tr> <tr> <td>张三</td> <td>25</td> <td>北京</td> </tr> </table>
功能
默认情况下,浏览器会加粗显示
<th>
内容并居中提供语义化标记,有助于屏幕阅读器识别表头
可以通过CSS进一步样式化
CSS扩展
/* 基本样式 */ th { font-weight: bold; text-align: center; background-color: #f2f2f2; padding: 8px; border: 1px solid #ddd; } /* 悬停效果 */ th:hover { background-color: #e6e6e6; } /* 斑马条纹表头 */ th:nth-child(even) { background-color: #f9f9f9; } /* 固定表头 */ thead th { position: sticky; top: 0; }
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。