示例工程 30-tables-lists
30-tables-lists/app/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>
<link rel="stylesheet" href="tokens.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="app">
<header class="site-header">
<span class="brand">DATA LAB</span>
<nav aria-label="页面导航">
<a href="#table">数据表</a>
<a href="#scroll">窄屏表</a>
<a href="#lists">列表</a>
<a href="#semantics">语义</a>
</nav>
</header>
<main class="page">
<p class="eyebrow">LESSON / 30</p>
<h1>表格要能读,列表要能扫</h1>
<p class="lead">
数字右对齐、表头粘住、窄屏可滚动;列表用对标记,读屏才知道结构。
</p>
<section class="panel" id="table">
<h2>1. 数据表格</h2>
<p>斑马纹、悬停高亮、数字右对齐、表头在容器内粘住。</p>
<div class="table-scroll">
<table class="data">
<caption>渠道表现(示例数据)</caption>
<thead>
<tr>
<th scope="col">渠道</th>
<th scope="col" class="num" aria-sort="descending">
<button class="sort" type="button">访问 <span aria-hidden="true">↓</span></button>
</th>
<th scope="col" class="num">转化率</th>
<th scope="col" class="num">收入</th>
</tr>
</thead>
<tbody>
<tr><th scope="row">自然搜索</th><td class="num">5,120</td><td class="num">3.8%</td><td class="num">¥12,480</td></tr>
<tr><th scope="row">邮件</th><td class="num">2,430</td><td class="num">5.1%</td><td class="num">¥8,320</td></tr>
<tr><th scope="row">社交</th><td class="num">1,860</td><td class="num">2.2%</td><td class="num">¥3,640</td></tr>
<tr><th scope="row">直接访问</th><td class="num">3,480</td><td class="num">4.4%</td><td class="num">¥9,120</td></tr>
<tr><th scope="row">推荐</th><td class="num">1,240</td><td class="num">6.0%</td><td class="num">¥5,980</td></tr>
<tr><th scope="row">付费广告</th><td class="num">2,980</td><td class="num">2.9%</td><td class="num">¥7,450</td></tr>
<tr><th scope="row">联盟</th><td class="num">860</td><td class="num">4.1%</td><td class="num">¥2,310</td></tr>
<tr><th scope="row">其他</th><td class="num">420</td><td class="num">1.8%</td><td class="num">¥980</td></tr>
</tbody>
<tfoot>
<tr><th scope="row">合计</th><td class="num">18,390</td><td class="num">3.9%</td><td class="num">¥50,280</td></tr>
</tfoot>
</table>
</div>
</section>
<section class="panel" id="scroll">
<h2>2. 窄屏表格</h2>
<p>容器横向滚动,首列 sticky;页面本身不横向滚动。</p>
<div class="table-scroll narrow">
<table class="data compact">
<thead>
<tr>
<th scope="col" class="sticky-col">月份</th>
<th scope="col" class="num">访问</th>
<th scope="col" class="num">注册</th>
<th scope="col" class="num">付费</th>
<th scope="col" class="num">收入</th>
</tr>
</thead>
<tbody>
<tr><th scope="row" class="sticky-col">1 月</th><td class="num">12,400</td><td class="num">1,204</td><td class="num">318</td><td class="num">¥38,200</td></tr>
<tr><th scope="row" class="sticky-col">2 月</th><td class="num">13,120</td><td class="num">1,310</td><td class="num">342</td><td class="num">¥41,600</td></tr>
<tr><th scope="row" class="sticky-col">3 月</th><td class="num">14,860</td><td class="num">1,488</td><td class="num">401</td><td class="num">¥49,300</td></tr>
<tr><th scope="row" class="sticky-col">4 月</th><td class="num">15,240</td><td class="num">1,522</td><td class="num">428</td><td class="num">¥52,780</td></tr>
</tbody>
</table>
</div>
</section>
<section class="panel" id="lists">
<h2>3. 列表</h2>
<h3>带标记的清单</h3>
<ul class="checklist">
<li>支持键盘导航</li>
<li>对比度达到 AA</li>
<li>窄屏无横向滚动</li>
</ul>
<h3>步骤</h3>
<ol class="steps">
<li>选模板</li>
<li>改内容</li>
<li>发布</li>
</ol>
<h3>术语表</h3>
<dl class="meta-list">
<dt>token</dt>
<dd>可复用的设计值。</dd>
<dt>sticky</dt>
<dd>在滚动到阈值前保持正常流。</dd>
</dl>
</section>
<section class="panel" id="semantics">
<h2>4. 语义清单</h2>
<ul class="notes">
<li>数据表用 <code>table</code>,不要用 Grid 假装。</li>
<li>表头用 <code>th scope</code>,行标题用 <code>scope="row"</code>。</li>
<li>列表用 <code>ul</code>/<code>ol</code>/<code>dl</code>,不要用 <code>div</code> 堆。</li>
<li>窄屏表格优先滚动,不要拆散单元格。</li>
</ul>
</section>
</main>
<footer class="site-footer">
<p>示例数据,仅用于教程演示。</p>
<p>TABLES & LISTS · 2026</p>
</footer>
</div>
</body>
</html>