表格标签
发布时间: 2025年6月23日 00:57作者: 似琼碧落浏览: 27 次
已发布
内容格式: Markdown字数: 1163 字符
表格标签
HTML 使用 <table>
创建表格,基本结构如下:
<table>
:表格容器<tr>
:表格行(table row)<th>
:表头单元格(加粗、居中)<td>
:普通单元格(table data)
示例 1:基本表格结构
<table border="1">
<tr>
<th>姓名</th>
<th>年龄</th>
</tr>
<tr>
<td>张三</td>
<td>25</td>
</tr>
<tr>
<td>李四</td>
<td>30</td>
</tr>
</table>
显示效果:
姓名 | 年龄 |
---|---|
张三 | 25 |
李四 | 30 |
示例 2:合并列(colspan)
<table border="1">
<tr>
<th>姓名</th>
<th colspan="2">联系方式</th>
</tr>
<tr>
<td>王五</td>
<td>邮箱</td>
<td>电话</td>
</tr>
</table>
姓名 | 联系方式 |
---|---|
王五 | 邮箱 |
示例 3:合并行(rowspan)
<table border="1">
<tr>
<th rowspan="2">类别</th>
<td>苹果</td>
</tr>
<tr>
<td>香蕉</td>
</tr>
</table>
类别 | 内容 |
---|---|
水果 | 苹果 |
香蕉 |
示例 4:添加标题(caption)
<table border="1">
<caption>学生成绩表</caption>
<tr>
<th>姓名</th>
<th>成绩</th>
</tr>
<tr>
<td>张三</td>
<td>92</td>
</tr>
</table>
表格上方将显示标题“学生成绩表”,
<caption>
是表格的说明文字。
✅ 建议开发中用 CSS 控制样式,不建议使用 `borde
分类:
html
最后更新: 2025年9月4日 20:43