示例工程 51-accessibility

51-accessibility/app/index.html

html · 3.8 KB

运行:CSS 与无障碍

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>CSS 与无障碍</title>
    <link rel="stylesheet" href="tokens.css" />
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <a class="skip-link" href="#main">跳到主内容</a>

    <div class="app">
      <header class="site-header">
        <span class="brand">A11Y LAB</span>
        <nav aria-label="页面导航">
          <a href="#contrast" aria-current="page">对比度</a>
          <a href="#focus">焦点</a>
          <a href="#states">状态</a>
          <a href="#notes">清单</a>
        </nav>
      </header>

      <main class="page" id="main">
        <p class="eyebrow">LESSON / 51</p>
        <h1>让每个人都能读完、点中、看懂</h1>
        <p class="lead">
          对比度、焦点、触控尺寸、减少动效与强制配色,是 CSS 无障碍的五个基本盘。
        </p>

        <section class="panel" id="contrast">
          <h2>1. 对比度</h2>
          <p>正文至少 4.5:1,大字号至少 3:1;不要只靠颜色传达信息。</p>

          <div class="contrast-grid">
            <div class="contrast-card contrast-pass">
              <span class="tag">AA 正文</span>
              <p>这段正文使用深色文字,对比度充足。</p>
            </div>
            <div class="contrast-card contrast-large">
              <span class="tag">AA 大字</span>
              <p class="large-text">大字号可以放宽到 3:1。</p>
            </div>
            <div class="contrast-card contrast-muted">
              <span class="tag">弱化文字</span>
              <p>弱化不等于不可读,仍要过 4.5:1。</p>
            </div>
          </div>
        </section>

        <section class="panel" id="focus">
          <h2>2. 焦点与触控目标</h2>
          <p>键盘 Tab 能看到焦点;按钮至少 44×44。</p>

          <div class="actions">
            <button class="btn" type="button">主要操作</button>
            <button class="btn btn--ghost" type="button">次要操作</button>
            <button class="icon-btn" type="button" aria-label="关闭">×</button>
            <a class="link" href="#focus">普通链接</a>
          </div>

          <div class="focus-card">
            <label for="email">工作邮箱</label>
            <input id="email" type="email" aria-describedby="email-hint" placeholder="you@example.com" />
            <p class="hint" id="email-hint">输入后失焦会校验格式。</p>
          </div>
        </section>

        <section class="panel" id="states">
          <h2>3. 状态与动效</h2>
          <p>错误有文字;减少动效下动画停止;强制配色下边框仍可见。</p>

          <p class="error-text" role="status" aria-live="polite">邮箱格式不正确,请检查后重试。</p>

          <div class="motion-box">
            <span class="motion-dot" aria-hidden="true"></span>
            <p>这个圆点在减少动效偏好下停止。</p>
          </div>

          <div class="forced-card">
            <p>强制配色模式下,这张卡片靠边框区分。</p>
          </div>
        </section>

        <section class="panel" id="notes">
          <h2>4. 检查清单</h2>
          <ul class="notes">
            <li>正文对比度 ≥ 4.5:1,大字 ≥ 3:1。</li>
            <li>焦点环可见,不要只改颜色。</li>
            <li>触控目标 ≥ 44×44 CSS 像素。</li>
            <li>错误有文字说明,不只靠红框。</li>
            <li>减少动效时停止装饰动画。</li>
          </ul>
        </section>
      </main>

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