示例工程 06-text-typography

06-text-typography/app/index.html

html · 2.7 KB

运行:文本与排版实验室

点击「运行示例」后,左侧显示源码、右侧显示运行结果;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="style.css" />
  </head>
  <body>
    <header class="site-header">
      <span class="brand">TYPE LAB</span>
      <nav aria-label="页面导航">
        <a href="#stack">字体</a>
        <a href="#measure">行宽</a>
        <a href="#wrap">断行</a>
      </nav>
    </header>

    <main class="page">
      <article class="essay">
        <p class="eyebrow">LESSON / 06</p>
        <h1>让文字好读,比让文字好看更难</h1>
        <p class="meta">2026-11-27 · 约 10 分钟阅读</p>

        <p class="lead">
          排版不是选一个漂亮字体。它决定读者读多快、读多久、会不会在第三段放弃。
          这一章只讲四件事:字体栈、字号、行高与行宽。
        </p>

        <section id="stack">
          <h2>字体栈:先保证有字可用</h2>
          <p>
            CSS 的 <code>font-family</code> 是一个列表,浏览器从左到右找第一个可用字体。
            系统字体栈让页面在 macOS、Windows、Linux 上都用本地字体,不下载、不闪烁。
          </p>
          <p class="sample-serif">这一段用衬线字体栈,适合长文阅读,但在小字号屏幕上可能不够清晰。</p>
          <p class="sample-mono">const typography = "monospace for code";</p>
        </section>

        <section id="measure">
          <h2>行宽:一行不要太多字</h2>
          <p>
            中文正文一行 25–35 个字比较舒适;英文大约 45–75 个字符。
            太宽,眼睛回行会迷路;太窄,换行太频繁,节奏被打断。
          </p>
          <p class="narrow">这一段被限制在 30ch 左右,读起来更紧凑,但长文会显得碎。</p>
        </section>

        <section id="wrap">
          <h2>断行与缩进</h2>
          <p class="indent">
            中文段落常用首行缩进两个字符,而不是用空格。`text-indent: 2em`
            会随字号缩放,复制到其它地方也不会带一堆空格。
          </p>
          <p class="balance">
            标题和短句可以用 <code>text-wrap: balance</code> 让多行长度更均匀,
            避免最后一行只剩一个词。
          </p>
        </section>

        <blockquote>
          <p>排版是把内容放进合适容器的手艺,不是给内容化妆。</p>
          <cite>—— 本章示例</cite>
        </blockquote>
      </article>
    </main>

    <footer class="site-footer">示例数据,仅用于教程演示。</footer>
  </body>
</html>