示例工程 31-article-section-aside

31-article-section-aside/demo-02-section-aside/index.html

html · 2.2 KB

运行:section 与 aside 演示

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

<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>section 与 aside 演示</title>
    <style>
      body { margin: 0; padding: 32px; background: #f8fafc; color: #0f172a; font-family: system-ui, sans-serif; line-height: 1.7; }
      .box { max-width: 760px; 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: 18px; }
      p { margin: 0 0 10px; color: #334155; }
      section { margin-top: 12px; padding: 12px; border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc; }
      aside { margin-top: 12px; padding: 12px; border-left: 4px solid #2563eb; background: #eff6ff; }
      .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
      .card { padding: 12px; border: 1px solid #e2e8f0; border-radius: 8px; background: #fff; }
      code { padding: 1px 5px; border-radius: 4px; background: #f1f5f9; font-family: ui-monospace, monospace; }
    </style>
  </head>
  <body>
    <h1>section 与 aside</h1>

    <div class="box">
      <h2>section 需要标题</h2>
      <section aria-labelledby="why-title">
        <h3 id="why-title">为什么需要标题</h3>
        <p>section 是主题分区,标题说明这个分区是什么。</p>
      </section>
      <section aria-labelledby="how-title">
        <h3 id="how-title">没有标题怎么办</h3>
        <p>如果只是布局分组,用 <code>div</code>,不要用 section。</p>
      </section>
    </div>

    <div class="box">
      <h2>aside 是附属内容</h2>
      <aside aria-label="相关链接">
        <p>相关链接、作者简介、术语解释适合放这里。</p>
      </aside>
    </div>

    <div class="box">
      <h2>卡片列表用 div 或 article</h2>
      <div class="cards">
        <article class="card">
          <h3>卡片一</h3>
          <p>每张卡片可以独立分发,用 article。</p>
        </article>
        <article class="card">
          <h3>卡片二</h3>
          <p>外层网格只是布局,用 div。</p>
        </article>
      </div>
    </div>
  </body>
</html>