示例工程 31-article-section-aside

31-article-section-aside/app/index.html

html · 5.1 KB

运行:article / 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>article / section / aside · 内容分区</title>
    <meta name="description" content="用 article、section、aside 表达文章、主题分区与附属内容。" />
    <style>
      * { box-sizing: border-box; }
      body {
        margin: 0;
        min-height: 100vh;
        padding: 28px 20px 40px;
        background: #f8fafc;
        color: #0f172a;
        font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
        line-height: 1.7;
      }
      .page { width: min(100%, 900px); 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; }
      article { padding: 22px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; }
      article > header { padding-bottom: 14px; border-bottom: 1px solid #e2e8f0; }
      .eyebrow { margin: 0; color: #64748b; font-size: 11px; letter-spacing: 0.18em; }
      h1 { margin: 6px 0 8px; font-size: clamp(30px, 6vw, 42px); line-height: 1.15; }
      .meta { margin: 0; color: #64748b; font-size: 13px; }
      section { margin-top: 22px; }
      h2 { margin: 0 0 8px; font-size: 21px; }
      h3 { margin: 0 0 6px; font-size: 16px; }
      p { margin: 0 0 10px; color: #334155; }
      ul { margin: 8px 0 10px; padding-left: 22px; color: #334155; }
      li + li { margin-top: 4px; }
      .comments article { margin-top: 12px; padding: 14px; border: 1px solid #e2e8f0; border-radius: 10px; background: #f8fafc; }
      .comments article p { margin: 0; }
      aside { margin-top: 22px; padding: 16px; border-left: 4px solid #2563eb; border-radius: 8px; background: #eff6ff; }
      aside h2 { margin: 0 0 8px; font-size: 17px; color: #1e3a8a; }
      aside ul { margin: 0; color: #1e3a8a; }
      aside a { color: #1d4ed8; }
      code { padding: 1px 5px; border-radius: 4px; background: #f1f5f9; font-family: ui-monospace, Menlo, monospace; font-size: 0.92em; }
      footer.page-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; }
      }
    </style>
  </head>
  <body>
    <div class="page">
      <header class="site-header">
        <span class="brand">BLOG / 2026</span>
        <nav aria-label="主导航">
          <a href="#post">文章</a>
          <a href="#comments">评论</a>
          <a href="#related">相关</a>
        </nav>
      </header>

      <main>
        <article id="post">
          <header>
            <p class="eyebrow">HTML / STRUCTURE</p>
            <h1>什么时候用 article,什么时候用 section</h1>
            <p class="meta">2026-11-28 · 林小满 · 预计阅读 6 分钟</p>
          </header>

          <section id="article">
            <h2>article 是可独立分发的内容</h2>
            <p>一篇博客、一条评论、一张卡片、一个论坛帖子,都可以是 <code>article</code>。</p>
            <p>判断标准:把它单独拿出去,是否仍然成立。</p>
          </section>

          <section id="section">
            <h2>section 是主题分区</h2>
            <p><code>section</code> 表示同一主题下的一组内容,通常带标题。</p>
            <p>没有标题的分组,用 <code>div</code> 更合适。</p>
          </section>

          <section id="aside">
            <h2>aside 是附属内容</h2>
            <p>相关链接、作者简介、术语解释可以放 <code>aside</code>。</p>
            <p>aside 不应承载页面的主要论证。</p>
          </section>

          <section id="comments" class="comments">
            <h2>评论</h2>
            <p>每条评论是独立的 <code>article</code>,整体放在「评论」这个 section 里。</p>

            <article>
              <h3>读者 A</h3>
              <p>这个判断标准很实用,我以后先问「能不能单独拿出去」。</p>
            </article>

            <article>
              <h3>读者 B</h3>
              <p>section 没有标题时确实不如 div,读屏也会困惑。</p>
            </article>
          </section>

          <footer>
            <p>标签:HTML · 语义 · article</p>
          </footer>
        </article>
      </main>

      <aside id="related" aria-labelledby="related-title">
        <h2 id="related-title">相关文章</h2>
        <ul>
          <li><a href="#article">article 的边界</a></li>
          <li><a href="#section">section 与标题</a></li>
          <li><a href="#aside">aside 的使用场景</a></li>
        </ul>
      </aside>

      <footer class="page-footer">
        <p>© 2026 示例博客 · 仅用于教学</p>
      </footer>
    </div>
  </body>
</html>