示例工程 45-modern-selectors
45-modern-selectors/demo-02-popover/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>原生 popover</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>原生 popover</h1>
<p>按钮与浮层只靠 HTML 属性与 CSS 连接。</p>
<button class="btn" type="button" popovertarget="pop">打开浮层</button>
<div id="pop" popover>
<strong>浮层内容</strong>
<p>点击外部或按 Esc 关闭。</p>
</div>
<details>
<summary>details 也能用 :open</summary>
<p>展开后 `<code>details:open</code>` 匹配。</p>
</details>
</body>
</html>