无法覆盖 CSS :root 变量 | --原色:橙色;不回应

can't override the CSS :root variable | --primary-color: orange; does not respond

这是我的 'root':

:root {

--primary-color: #B92430;
}

但我无法在随后的 classes:

中覆盖它
h1 {

--primary-color: orange;
font-family: 'New Tegomin', sans-serif;

}

h1class不响应变量

虽然您已经定义(并重新定义)了变量是什么,但您还没有说明 属性 它应该适用于什么。在这里我假设你的意思是 color.

:root {
  --primary-color: green;
}

h1.change {
  --primary-color: red;
  color: var(--primary-color);
}
<h1 class="change">Lorem, ipsum.</h1>