示例工程 41-accessibility-audit

41-accessibility-audit/app/index.html

html · 10 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>
    <meta name="description" content="从范围、工具、问题分级到修复与回归,完整走一遍可访问性审计。" />
    <style>
      * { box-sizing: border-box; }
      body {
        margin: 0;
        min-height: 100vh;
        padding: 30px 20px 40px;
        background: #f8fafc;
        color: #0f172a;
        font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
        line-height: 1.7;
      }
      .skip { position: absolute; left: -9999px; top: 0; padding: 8px 12px; background: #2563eb; color: #fff; }
      .skip:focus { left: 8px; top: 8px; z-index: 10; }
      .page { width: min(100%, 820px); 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: 26px 0; }
      .eyebrow { margin: 0; color: #64748b; font-size: 11px; letter-spacing: 0.18em; }
      h1 { margin: 6px 0 10px; font-size: clamp(30px, 6vw, 42px); line-height: 1.15; }
      .lead { margin: 0 0 20px; color: #334155; font-size: 17px; }
      .stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0 0 8px; padding: 0; list-style: none; }
      .stats li { padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 10px; background: #fff; }
      .stats strong { display: block; font-size: 22px; line-height: 1.3; }
      .stats span { color: #64748b; font-size: 12px; }
      section { margin-top: 26px; padding-top: 18px; border-top: 1px solid #e2e8f0; }
      h2 { margin: 0 0 10px; font-size: 21px; }
      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; }
      table { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
      caption { padding: 8px; text-align: left; color: #475569; font-size: 13px; }
      th, td { padding: 8px 10px; border-bottom: 1px solid #e2e8f0; text-align: left; vertical-align: top; }
      thead th { background: #f1f5f9; }
      .tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 12px; font-weight: 600; }
      .tag.serious { background: #fee2e2; color: #991b1b; }
      .tag.moderate { background: #fef3c7; color: #92400e; }
      .tag.minor { background: #e0f2fe; color: #075985; }
      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; }
      details { margin: 10px 0; padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 8px; background: #fff; }
      summary { cursor: pointer; font-weight: 600; }
      .note { padding: 12px 14px; border-left: 4px solid #2563eb; border-radius: 6px; background: #eff6ff; color: #1e3a8a; font-size: 14px; }
      footer { margin-top: 28px; padding-top: 14px; border-top: 1px solid #e2e8f0; color: #64748b; font-size: 12px; }
      @media (max-width: 560px) {
        body { padding: 18px 14px 32px; }
        .site-header { flex-direction: column; }
        .stats { grid-template-columns: 1fr; }
      }
    </style>
  </head>
  <body>
    <a class="skip" href="#main">跳到审计结果</a>

    <div class="page">
      <header class="site-header">
        <span class="brand">A11Y AUDIT / 2026</span>
        <nav aria-label="页内导航">
          <a href="#scope">范围</a>
          <a href="#results">问题</a>
          <a href="#fixes">修复</a>
          <a href="#checklist">清单</a>
        </nav>
      </header>

      <main id="main">
        <p class="eyebrow">PROJECT / 41</p>
        <h1>可访问审计</h1>
        <p class="lead">
          审计不是跑一次工具就结束,而是「定范围、找问题、分级、修复、回归」的完整闭环。本页是一份虚构站点的审计记录。
        </p>

        <ul class="stats">
          <li><strong>16</strong><span>发现问题</span></li>
          <li><strong>3</strong><span>严重(用户无法完成任务)</span></li>
          <li><strong>2 天</strong><span>修复与回归用时</span></li>
        </ul>

        <section id="scope" aria-labelledby="scope-title">
          <h2 id="scope-title">1. 审计范围</h2>
          <p>范围写不清,结论就没有意义。本次审计覆盖:</p>
          <ul>
            <li>首页、列表页、详情页、注册表单四个模板;</li>
            <li>桌面 1280px 与移动 390px 两个宽度;</li>
            <li>键盘、NVDA、VoiceOver、200% 缩放与高对比;</li>
            <li>Chrome 156、Firefox、Safari 最新版本。</li>
          </ul>
          <p class="note">不在范围内:第三方支付页、邮件模板、原生 App。范围外的部分在报告里注明「未覆盖」,不写成「通过」。</p>
        </section>

        <section id="results" aria-labelledby="results-title">
          <h2 id="results-title">2. 问题清单</h2>
          <p>按影响分级:严重 = 任务无法完成;中等 = 明显受阻但有替代;轻微 = 体验瑕疵。</p>

          <table>
            <caption>本次审计的主要问题(节选)</caption>
            <thead>
              <tr>
                <th scope="col">编号</th>
                <th scope="col">问题</th>
                <th scope="col">位置</th>
                <th scope="col">级别</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <th scope="row">A-01</th>
                <td>注册按钮是 <code>div</code>,键盘无法提交</td>
                <td>注册表单</td>
                <td><span class="tag serious">严重</span></td>
              </tr>
              <tr>
                <th scope="row">A-02</th>
                <td>邮箱输入框没有标签,读屏只读「编辑框」</td>
                <td>注册表单</td>
                <td><span class="tag serious">严重</span></td>
              </tr>
              <tr>
                <th scope="row">A-03</th>
                <td>对话框打开后焦点留在背景,Esc 无法关闭</td>
                <td>详情页</td>
                <td><span class="tag serious">严重</span></td>
              </tr>
              <tr>
                <th scope="row">A-04</th>
                <td>列表页标题从 h1 直接跳到 h3</td>
                <td>列表页</td>
                <td><span class="tag moderate">中等</span></td>
              </tr>
              <tr>
                <th scope="row">A-05</th>
                <td>错误只用红色边框提示,没有文字</td>
                <td>注册表单</td>
                <td><span class="tag moderate">中等</span></td>
              </tr>
              <tr>
                <th scope="row">A-06</th>
                <td>图片 alt 写成文件名 <code>hero-final-2.png</code></td>
                <td>首页</td>
                <td><span class="tag minor">轻微</span></td>
              </tr>
            </tbody>
          </table>
        </section>

        <section id="fixes" aria-labelledby="fixes-title">
          <h2 id="fixes-title">3. 修复示例</h2>
          <p>每条问题都要给出「位置 + 原因 + 修法 + 验证方式」,而不是只写「请修复」。</p>

          <h3>把 div 按钮换成原生按钮</h3>
          <pre><code>&lt;!-- 修复前:键盘无法触发 --&gt;
&lt;div class="btn" role="button" tabindex="0"&gt;注册&lt;/div&gt;

&lt;!-- 修复后:Enter / Space 都能触发 --&gt;
&lt;button type="submit"&gt;注册&lt;/button&gt;</code></pre>

          <h3>给输入框补可见标签</h3>
          <pre><code>&lt;label for="email"&gt;邮箱&lt;/label&gt;
&lt;input id="email" type="email" autocomplete="email"&gt;</code></pre>
        </section>

        <section id="checklist" aria-labelledby="checklist-title">
          <h2 id="checklist-title">4. 人工检查清单</h2>
          <p>自动化只能覆盖一部分,下面这些必须人工走。</p>

          <details>
            <summary>键盘与焦点(6 项)</summary>
            <ul>
              <li>Tab 能到达所有可操作元素,Shift+Tab 能返回;</li>
              <li>焦点环始终可见;</li>
              <li>没有正数 tabindex;</li>
              <li>对话框打开后焦点进入,关闭后返回;</li>
              <li>没有键盘陷阱;</li>
              <li>skip link 可用。</li>
            </ul>
          </details>

          <details>
            <summary>读屏与名称(6 项)</summary>
            <ul>
              <li>每页一个 h1,标题不跳级;</li>
              <li>地标完整且命名;</li>
              <li>链接文字可独立理解;</li>
              <li>图片 alt 准确;</li>
              <li>表单控件有名称、错误与状态;</li>
              <li>表格有 caption 与表头。</li>
            </ul>
          </details>

          <details>
            <summary>视觉与适配(4 项)</summary>
            <ul>
              <li>文字对比度达到 4.5:1;</li>
              <li>200% 缩放不重叠、不截断;</li>
              <li>不只靠颜色传达信息;</li>
              <li>触控目标不小于 44×44。</li>
            </ul>
          </details>
        </section>

        <section id="report" aria-labelledby="report-title">
          <h2 id="report-title">5. 报告怎么写</h2>
          <ol>
            <li>结论先行:能不能用、卡在哪。</li>
            <li>列范围与未覆盖项。</li>
            <li>按级别列问题,附复现步骤。</li>
            <li>给修复建议与验证方式。</li>
            <li>约定回归时间与负责人。</li>
          </ol>
        </section>
      </main>

      <footer>
        <p>审计对象与数据均为虚构,仅用于教学。</p>
      </footer>
    </div>
  </body>
</html>