示例工程 13-images

13-images/demo-01-alt/index.html

html · 1.6 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>
    <style>
      body { margin: 0; padding: 32px; background: #f8fafc; color: #0f172a; font-family: system-ui, sans-serif; line-height: 1.75; }
      .box { max-width: 720px; margin-bottom: 16px; padding: 18px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; }
      h1 { margin: 0 0 16px; font-size: 28px; }
      h2 { margin: 0 0 8px; font-size: 17px; }
      p { margin: 0 0 10px; color: #334155; }
      img { max-width: 100%; height: auto; border-radius: 8px; }
      figure { margin: 8px 0 0; }
      figcaption { margin-top: 6px; color: #64748b; font-size: 13px; }
      a { color: #2563eb; }
    </style>
  </head>
  <body>
    <h1>替代文本演示</h1>

    <div class="box">
      <h2>信息图:描述内容</h2>
      <figure>
        <img src="assets/chart.svg" alt="季度访问量柱状图:Q1 到 Q4 逐季上升" width="640" height="360" />
        <figcaption>读屏会读出趋势,而不是「图片」。</figcaption>
      </figure>
    </div>

    <div class="box">
      <h2>装饰图:alt 为空</h2>
      <p>下面的分隔线只是装饰,alt="",读屏会跳过。</p>
      <img src="assets/divider.svg" alt="" width="400" height="40" />
    </div>

    <div class="box">
      <h2>功能图:描述动作</h2>
      <p><a href="assets/manual.txt" download="manual.txt"><img src="assets/download.svg" alt="下载用户手册" width="48" height="48" /> 用户手册</a></p>
    </div>
  </body>
</html>