示例工程 09-lists
09-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>列表 · ul / ol / dl</title>
<meta name="description" content="无序列表、有序列表、描述列表与嵌套的最小示例。" />
<style>
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
padding: 32px 20px;
background: #f8fafc;
color: #0f172a;
font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
line-height: 1.75;
}
.page { width: min(100%, 780px); margin: 0 auto; }
.site-header { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 1px solid #e2e8f0; }
.brand { font-weight: 700; letter-spacing: 0.14em; font-size: 13px; }
nav a { color: #2563eb; font-size: 13px; text-decoration: none; }
nav a + a { margin-left: 14px; }
main { padding: 32px 0; }
.eyebrow { margin: 0; color: #64748b; font-size: 11px; letter-spacing: 0.18em; }
h1 { margin: 6px 0 12px; font-size: clamp(30px, 6vw, 44px); line-height: 1.15; }
.lead { margin: 0 0 24px; color: #334155; font-size: 17px; }
section { margin-top: 28px; padding-top: 20px; border-top: 1px solid #e2e8f0; }
h2 { margin: 0 0 10px; font-size: 23px; }
h3 { margin: 16px 0 6px; font-size: 16px; }
p { margin: 0 0 12px; color: #334155; }
ul, ol { margin: 8px 0 12px; padding-left: 24px; color: #334155; }
li + li { margin-top: 4px; }
li > ul, li > ol { margin-top: 4px; }
dl { margin: 10px 0; padding: 12px 14px; border-left: 3px solid #2563eb; border-radius: 6px; background: #f8fafc; }
dt { font-weight: 600; color: #0f172a; }
dd { margin: 2px 0 10px 0; color: #334155; }
dd:last-child { margin-bottom: 0; }
code { padding: 1px 5px; border-radius: 4px; background: #f1f5f9; font-family: ui-monospace, Menlo, monospace; font-size: 0.92em; }
pre { margin: 10px 0 0; padding: 14px; overflow-x: auto; border-radius: 10px; background: #0f172a; color: #e2e8f0; font-size: 12px; line-height: 1.7; }
pre code { padding: 0; background: none; color: inherit; }
footer { margin-top: 32px; padding-top: 16px; border-top: 1px solid #e2e8f0; color: #64748b; font-size: 12px; }
@media (max-width: 560px) {
.site-header { flex-direction: column; }
nav a + a { margin-left: 12px; }
}
</style>
</head>
<body>
<div class="page">
<header class="site-header">
<span class="brand">LIST NOTES</span>
<nav aria-label="页内导航">
<a href="#ul">无序</a>
<a href="#ol">有序</a>
<a href="#dl">描述</a>
<a href="#nesting">嵌套</a>
</nav>
</header>
<main>
<p class="eyebrow">LESSON / 09</p>
<h1>列表</h1>
<p class="lead">
并列用无序列表,步骤用有序列表,术语与解释用描述列表。列表不是「加圆点」,是把一组项目的关系写进结构。
</p>
<section id="ul">
<h2>1. 无序列表</h2>
<p>项目之间没有先后顺序时,用 <code>ul</code>。</p>
<ul>
<li>语义化标签</li>
<li>键盘可操作</li>
<li>对比度达标</li>
<li>320px 不溢出</li>
</ul>
<p>读屏会播报「列表,四项」,用户可以按列表跳转。</p>
</section>
<section id="ol">
<h2>2. 有序列表</h2>
<p>有先后顺序时,用 <code>ol</code>。浏览器自动编号,顺序改变时不用手改数字。</p>
<ol>
<li>打开终端</li>
<li>进入项目目录</li>
<li>运行校验脚本</li>
</ol>
<p>从第 3 步开始:<code>start="3"</code>;倒序:<code>reversed</code>。</p>
<ol start="3">
<li>发布</li>
<li>跑 smoke</li>
<li>记录部署</li>
</ol>
</section>
<section id="dl">
<h2>3. 描述列表</h2>
<p>术语与解释成对出现时,用 <code>dl</code>,术语用 <code>dt</code>,解释用 <code>dd</code>。</p>
<dl>
<dt>HTML</dt>
<dd>描述文档结构。</dd>
<dt>CSS</dt>
<dd>描述视觉样式。</dd>
<dt>DOM</dt>
<dd>浏览器解析后的文档对象模型。</dd>
<dd>可以用脚本查询与修改。</dd>
</dl>
<p>一个术语可以有多个 <code>dd</code>,表示多条解释。</p>
</section>
<section id="nesting">
<h2>4. 嵌套</h2>
<p>子列表放在父项的 <code>li</code> 里,不能直接放在 <code>ul</code> 下。</p>
<ul>
<li>
前端
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
</li>
<li>
后端
<ul>
<li>Node.js</li>
</ul>
</li>
</ul>
<p>嵌套层数控制在两到三层,太深读者会迷路。</p>
</section>
</main>
<footer>
<p>示例数据,仅用于教学。</p>
</footer>
</div>
</body>
</html>