示例工程 20-table-complex
20-table-complex/demo-01-spans/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>合并单元格演示</title>
<style>
body { margin: 0; padding: 32px; background: #f8fafc; color: #0f172a; font-family: system-ui, sans-serif; line-height: 1.7; }
.box { max-width: 760px; margin-bottom: 16px; padding: 18px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; }
h1 { margin: 0 0 16px; font-size: 28px; }
h2 { margin: 0 0 8px; font-size: 17px; }
p { margin: 0 0 10px; color: #334155; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
caption { padding: 6px 8px; text-align: left; color: #475569; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid #e2e8f0; text-align: left; }
thead th { background: #f1f5f9; }
tbody th { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot th, tfoot td { background: #f8fafc; font-weight: 600; border-top: 2px solid #cbd5e1; }
</style>
</head>
<body>
<h1>合并单元格</h1>
<div class="box">
<h2>两级表头 + 合计</h2>
<table>
<caption>2026 年部门季度预算(万元)</caption>
<thead>
<tr>
<th rowspan="2" scope="col">部门</th>
<th colspan="2" scope="colgroup">上半年</th>
<th colspan="2" scope="colgroup">下半年</th>
</tr>
<tr>
<th scope="col">Q1</th>
<th scope="col">Q2</th>
<th scope="col">Q3</th>
<th scope="col">Q4</th>
</tr>
</thead>
<tbody>
<tr><th scope="row">产品部</th><td class="num">60</td><td class="num">60</td><td class="num">70</td><td class="num">70</td></tr>
<tr><th scope="row">工程部</th><td class="num">90</td><td class="num">90</td><td class="num">110</td><td class="num">110</td></tr>
</tbody>
<tfoot>
<tr><th scope="row">合计</th><td colspan="4" class="num">730</td></tr>
</tfoot>
</table>
</div>
</body>
</html>