示例工程 26-css-variables

26-css-variables/demo-02-fallback/index.html

html · 0.7 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>三个块,展示「有回退」「无回退」「已定义」的差别。</p>

    <div class="row">
      <div class="box with-fallback">var(--brand, 橙色)</div>
      <div class="box no-fallback">var(--brand) 未定义</div>
      <div class="box defined">var(--brand) 已定义</div>
    </div>

    <p class="hint">
      没有回退且变量未定义时,整条声明在计算值阶段失效,背景回到初始值。
    </p>
  </body>
</html>