示例工程 41-has-is-where
41-has-is-where/demo-01-has/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>:has 关系选择</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>:has 看内容</h1>
<div class="cards">
<article class="card">
<span class="badge">NEW</span>
<h2>有徽标</h2>
<p>父级卡片被 :has(.badge) 命中。</p>
</article>
<article class="card">
<h2>没有徽标</h2>
<p>保持普通边框。</p>
</article>
</div>
<div class="field">
<label for="mail">邮箱</label>
<input id="mail" type="email" value="nope" required />
<p class="hint">值不合法,整块变红。</p>
</div>
</body>
</html>