[英]Is "--" a valid CSS3 identifier?
According the CSS Level 3 specification , for parsing the start of an identifier, you:根据 CSS 3 级规范,为了解析标识符的开头,您:
Check if three code points would start an identifier检查三个代码点是否会开始一个标识符
Look at the first code point:看第一个代码点:
-
, then we have a valid identifier if:-
,那么我们有一个有效的标识符,如果:
[a-zA-Z_]
or non-ASCII).[a-zA-Z_]
或非 ASCII)。-
.-
。 Otherwise, we do not have a valid identifier start.否则,我们没有有效的标识符开始。 After determining if we have a valid identifier start, the only requirements to have a valid
<ident-token>
is we have 0 or more of any combination of the following:在确定我们是否有一个有效的标识符开始之后,拥有一个有效的
<ident-token>
的唯一要求是我们有 0 个或多个以下任意组合:
_
or -
_
或-
Since we do not require any characters following an identifier start token, this would suggest that --
is a valid identifier, even if never supported by any browser or framework.由于我们不需要标识符开始标记后面的任何字符,这表明
--
是一个有效的标识符,即使任何浏览器或框架都不支持。 However, even official CSS validation services (maintained by those that design the CSS specifications) do not consider this a valid identifier.然而,即使是官方的 CSS 验证服务(由设计 CSS 规范的人员维护)也不认为这是一个有效的标识符。 Is this merely a bug in the validation service?
这仅仅是验证服务中的一个错误吗?
Yes it's valid and it works.是的,它是有效的并且有效。 It's the shortest custom property (aka CSS variable) that you can define:
这是您可以定义的最短的自定义属性(又名 CSS 变量):
body { --:red; background:var(--); }
Related: Can a css variable name start with a number?相关: css 变量名可以以数字开头吗?
The --
custom property identifier is reserved for future use , but current browsers incorrectly treat it as a valid custom property. --
自定义属性标识符保留供将来使用,但当前浏览器错误地将其视为有效的自定义属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.