示例工程 32-states-focus
32-states-focus/demo-02-focus/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>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<a class="skip" href="#main">跳到正文</a>
<h1>焦点的三种用法</h1>
<section id="main">
<h2>focus-visible</h2>
<p>按 Tab 到按钮:出现焦点环;鼠标点击不出现。</p>
<button class="btn" type="button">键盘试试</button>
<h2>focus-within</h2>
<div class="card">
<label for="email">邮箱</label>
<input id="email" type="email" placeholder="you@example.com" />
</div>
<p class="hint">输入框聚焦时,整张卡片显示轮廓。</p>
</section>
</body>
</html>