示例工程 26-css-variables

26-css-variables/demo-01-scope/index.html

html · 0.8 KB

运行:变量的作用域

点击「运行示例」后,左侧显示源码、右侧显示运行结果;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>
    <h1>变量的作用域</h1>
    <p>同一套组件 CSS,两个卡片各自定义 <code>--accent</code>。</p>

    <div class="cards">
      <article class="card blue">
        <h2>蓝色</h2>
        <p>继承 <code>:root</code> 的 <code>--accent</code>。</p>
        <button type="button">按钮</button>
      </article>

      <article class="card pink">
        <h2>粉色</h2>
        <p>在本卡片上覆盖 <code>--accent</code>。</p>
        <button type="button">按钮</button>
      </article>
    </div>
  </body>
</html>