【发布时间】:2020-06-17 08:20:07
【问题描述】:
嗯,我想在我的 js 代码中使用一些 css 变量。
这是我的 .css 文件和 .js 代码的一部分:
const root = document.querySelector(":root");
const msgColor = getComputedStyle(root).getPropertyValue("--msg-color");
console.log(msgColor);
:root {
--msg-color: crimson;
--msg-text: floralwhite;
}
问题在于,在 chrome、safari 和新 Edge 中,我的常量中的颜色值是正确的,但在 Firefox 中却不起作用。
有什么想法吗? 谢谢。
【问题讨论】:
-
"在 chrome、firefox 和新的 Edge 中我做对了...,但在 firefox 中不起作用"您的代码最终在哪个浏览器中“运行”不工作”? (代码似乎可以在 FF77 中正常工作。)
-
对不起,我拼错了。在 chrome、safari 和 new edge 中工作。在 Firefox 中它没有。
标签: javascript firefox getcomputedstyle getpropertyvalue