简体   繁体   English

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

[英]Can a css variable name start with a number?

I want to know if it is valid to define a css variable that starts with a number like this,我想知道定义一个以这样的数字开头的 css 变量是否有效,

:root { --1space: 32px; }

this works just fine with Chrome, however that code is not being validated by https://jigsaw.w3.org/css-validator/ also VSCode draws a red line under the variable name.这适用于 Chrome,但是https://jigsaw.w3.org/css-validator/没有验证该代码,VSCode 在变量名下画了一条红线。

if css variable names are idents then it should be ok to start with a number by this diagram;如果 css 变量名称是 idents 则应该可以通过此图以数字开头;

https://www.w3.org/TR/css-syntax-3/#ident-token-diagram https://www.w3.org/TR/css-syntax-3/#ident-token-diagram

Yes it's valid.是的,它是有效的。 If we follow the definition in the speficiation :如果我们遵循规范中的定义

A custom property is any property whose name starts with two dashes (U+002D HYPHEN-MINUS), like --foo .自定义属性是名称以两个破折号 (U+002D HYPHEN-MINUS) 开头的任何属性,例如--foo The <custom-property-name> production corresponds to this: it's defined as any valid identifier that starts with two dashes <custom-property-name>产生式对应于:它被定义为以两个破折号开头的任何有效标识符

And

identifier标识符

A portion of the CSS source that has the same syntax as an <ident-token> . CSS 源的一部分,与<ident-token>具有相同的语法。 Also appears in <at-keyword-token> , <function-token> , <hash-token> with the "id" type flag, and the unit of <dimension-token> .也出现在<at-keyword-token><function-token><hash-token>中,带有“id”类型标志和<dimension-token>的单位。

在此处输入图像描述

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM