示例工程 32-details-summary
32-details-summary/demo-02-nested/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;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.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; }
details details { background: #f8fafc; }
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; }
</style>
</head>
<body>
<h1>嵌套与手风琴</h1>
<div class="box">
<h2>嵌套 details</h2>
<details>
<summary>外层问题</summary>
<p>外层内容。</p>
<details>
<summary>内层问题</summary>
<p>内层内容,只有外层展开后才可见。</p>
</details>
</details>
</div>
<div class="box">
<h2>手风琴</h2>
<details name="panel" open>
<summary>面板一</summary>
<p>同 name 的 details 互斥。</p>
</details>
<details name="panel">
<summary>面板二</summary>
<p>打开这个,面板一会自动关闭。</p>
</details>
</div>
</body>
</html>