自定义 CSS 属性是否使用一个或两个前导破折号? [英] Do custom CSS properties use one leading dash or two?

查看:34
本文介绍了自定义 CSS 属性是否使用一个或两个前导破折号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#elem {
  -myCustom: 99;
}

#elem {
  --myCustom: 99;
}

我在网上的例子中看到了上述两种方法.两者有什么区别?

I have seen both of the above used in examples online. What the difference between the two?

尝试在 JavaScript 中访问自定义属性返回 null..

Trying to access custom properties in JavaScript returns null..

#elem {
-myCustom: 99;
}

<div id="elem">some text</div>

elem = document.getElementById("elem");
style= window.getComputedStyle(elem);
value = style.getPropertyValue('-myCustom');
alert(value);

推荐答案

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆