示例工程 32-details-summary

32-details-summary/demo-01-basic/index.html

html · 1.7 KB

运行:details 基础演示

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

<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>details 基础演示</title>
    <style>
      body { margin: 0; padding: 32px; background: #f8fafc; color: #0f172a; font-family: system-ui, sans-serif; line-height: 1.7; }
      .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; }
      details { margin: 8px 0; padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 8px; }
      summary { cursor: pointer; font-weight: 600; }
      details p { margin: 8px 0 0; }
      code { padding: 1px 5px; border-radius: 4px; background: #f1f5f9; font-family: ui-monospace, monospace; }
      pre { margin: 8px 0 0; padding: 10px; overflow-x: auto; border-radius: 8px; background: #0f172a; color: #e2e8f0; font-size: 12px; }
    </style>
  </head>
  <body>
    <h1>details 基础</h1>

    <div class="box">
      <h2>三个可折叠问题</h2>
      <details open>
        <summary>第一个问题</summary>
        <p>open 让它在初始状态展开。</p>
      </details>
      <details>
        <summary>第二个问题</summary>
        <p>点击 summary 或按 Enter/Space 展开。</p>
      </details>
      <details>
        <summary>第三个问题</summary>
        <p>读屏会播报展开/收起状态。</p>
      </details>
    </div>

    <div class="box">
      <h2>结构</h2>
      <pre>&lt;details open&gt;
  &lt;summary&gt;问题&lt;/summary&gt;
  &lt;p&gt;答案&lt;/p&gt;
&lt;/details&gt;</pre>
    </div>
  </body>
</html>