示例工程 05-comments-entities

05-comments-entities/app/index.html

html · 5.2 KB

运行:注释、实体与空白 · HTML 笔记

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

<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>注释、实体与空白 · HTML 笔记</title>
    <meta name="description" content="HTML 注释、字符实体与空白折叠的最小示例。" />
    <style>
      * { box-sizing: border-box; }
      body {
        margin: 0;
        min-height: 100vh;
        padding: 32px 20px;
        background: #f8fafc;
        color: #0f172a;
        font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
        line-height: 1.75;
      }
      .page { width: min(100%, 780px); 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: 32px 0; }
      .eyebrow { color: #64748b; font-size: 11px; letter-spacing: 0.18em; }
      h1 { margin: 6px 0 12px; font-size: clamp(30px, 6vw, 46px); line-height: 1.1; }
      .lead { margin: 0 0 20px; color: #334155; font-size: 17px; }
      section { margin-top: 24px; padding: 20px; border: 1px solid #e2e8f0; border-radius: 14px; background: #fff; }
      h2 { margin: 0 0 10px; font-size: 20px; }
      p { margin: 0 0 10px; color: #334155; }
      ul { margin: 8px 0 0; padding-left: 22px; color: #334155; }
      li + li { margin-top: 4px; }
      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; }
      table { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 13px; }
      th, td { padding: 8px 10px; border-bottom: 1px solid #e2e8f0; text-align: left; vertical-align: top; }
      th { background: #f1f5f9; font-weight: 600; }
      .demo { padding: 14px; border: 1px dashed #cbd5e1; border-radius: 10px; background: #f8fafc; }
      .spaced { white-space: pre; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
      footer { padding-top: 18px; border-top: 1px solid #e2e8f0; color: #64748b; font-size: 12px; }
      @media (max-width: 560px) {
        .site-header { flex-direction: column; }
        table { display: block; overflow-x: auto; }
      }
    </style>
  </head>
  <body>
    <div class="page">
      <header class="site-header">
        <span class="brand">HTML NOTES</span>
        <nav aria-label="页面导航">
          <a href="#comments">注释</a>
          <a href="#entities">实体</a>
          <a href="#whitespace">空白</a>
        </nav>
      </header>

      <main>
        <p class="eyebrow">LESSON / 05</p>
        <h1>注释、实体与空白</h1>
        <p class="lead">
          注释写给维护者,实体解决「字符与语法冲突」,空白由 HTML 规则折叠。三者都影响你看到的文字。
        </p>

        <section id="comments">
          <h2>1. 注释</h2>
          <p>注释不会被显示,也不会被读屏读出。</p>
          <pre><code>&lt;!-- 这是注释 --&gt;
&lt;section id="work"&gt;…&lt;/section&gt;</code></pre>
          <p>注释适合标注区块用途,不要写密码、token 或内部地址。</p>
        </section>

        <section id="entities">
          <h2>2. 字符实体</h2>
          <p>HTML 里 <code>&lt;</code> 与 <code>&amp;</code> 有特殊含义,要写成实体。</p>
          <table>
            <thead>
              <tr><th>字符</th><th>实体</th><th>用途</th></tr>
            </thead>
            <tbody>
              <tr><td>&lt;</td><td><code>&amp;lt;</code></td><td>小于号</td></tr>
              <tr><td>&gt;</td><td><code>&amp;gt;</code></td><td>大于号</td></tr>
              <tr><td>&amp;</td><td><code>&amp;amp;</code></td><td>和号</td></tr>
              <tr><td>"</td><td><code>&amp;quot;</code></td><td>双引号</td></tr>
              <tr><td>©</td><td><code>&amp;copy;</code></td><td>版权</td></tr>
              <tr><td>—</td><td><code>&amp;mdash;</code></td><td>长破折号</td></tr>
              <tr><td>空格</td><td><code>&amp;nbsp;</code></td><td>不换行空格</td></tr>
            </tbody>
          </table>
        </section>

        <section id="whitespace">
          <h2>3. 空白</h2>
          <p>普通段落里的多个空格、换行会折叠成一个空格:</p>
          <div class="demo">
            <p>这里      有多个空格
              和换行,但浏览器只显示一个空格。</p>
          </div>
          <p><code>pre</code> 会保留空白:</p>
          <pre><code>第一行
  第二行缩进
    第三行缩进</code></pre>
          <p><code>br</code> 强制换行,<code>wbr</code> 只建议换行点。</p>
        </section>
      </main>

      <footer>
        <p>&copy; 2026 HTML 笔记 &mdash; 示例数据</p>
      </footer>
    </div>
  </body>
</html>