示例工程 18-table-basics
18-table-basics/demo-01-basic/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: 720px; 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; }
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>caption + 三个分组</h2>
<table>
<caption>2026 年季度访问与转化</caption>
<thead>
<tr>
<th scope="col">季度</th>
<th scope="col" class="num">访问量</th>
<th scope="col" class="num">转化</th>
</tr>
</thead>
<tbody>
<tr><th scope="row">Q1</th><td class="num">1200</td><td class="num">36</td></tr>
<tr><th scope="row">Q2</th><td class="num">1500</td><td class="num">45</td></tr>
<tr><th scope="row">Q3</th><td class="num">1800</td><td class="num">54</td></tr>
</tbody>
<tfoot>
<tr><th scope="row">合计</th><td class="num">4500</td><td class="num">135</td></tr>
</tfoot>
</table>
</div>
<div class="box">
<h2>结构回顾</h2>
<p>caption 说明整张表;thead 是列名;tbody 是数据;tfoot 是汇总。</p>
<p>没有表头的表格,读屏只能读一串数字,不知道每列代表什么。</p>
</div>
</body>
</html>