gpt4 book ai didi

css - css 变量名可以以数字开头吗?

转载 作者:行者123 更新时间:2023-12-04 07:51:38 25 4
gpt4 key购买 nike

我想知道定义一个以这样的数字开头的css变量是否有效,

:root { --1space: 32px; }
这在 Chrome 上工作得很好,但是代码没有被 https://jigsaw.w3.org/css-validator/ 验证,而且 VSCode 在变量名下画了一条红线。
如果 css 变量名是 idents,那么从这个图表中以数字开头应该没问题;
https://www.w3.org/TR/css-syntax-3/#ident-token-diagram

最佳答案

是的,它是有效的。如果我们关注 the definition in the speficiation :

A custom property is any property whose name starts with two dashes (U+002D HYPHEN-MINUS), like --foo. The <custom-property-name> production corresponds to this: it’s defined as any valid identifier that starts with two dashes



identifier

A portion of the CSS source that has the same syntax as an <ident-token>. Also appears in <at-keyword-token>, <function-token>, <hash-token> with the "id" type flag, and the unit of <dimension-token>.


enter image description here

:root {
--2222:red;
}

body {
background:var(--2222);
}

关于css - css 变量名可以以数字开头吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66941906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com