<custom-ident>

<custom-ident> 指用户自定义字符串标识符。一种CSS 数据类型;要区分大小写,值不能有任何歧义。

语法

<custom-ident> 语法同 CSS 属性名相似,但它是区分大小写的。可以由以下字符组成:

  • 字母 (A - Z, a - z),
  • 十进制数 (0 - 9),
  • 连字符 (-),
  • 下划线 (_),
  • 转义字符 ( \),
  • Unicode 编码(格式:转义字符(\)后跟 1 到 6 位十六进制数)

注意:id1, Id1, iD1ID1都是不同标识符,因为标识符是区分大小写的。另一方面,因为可以解码,所以 toto\?toto\3F 是相同的。

禁用值

<custom-ident> 不能用单引号或双引号包起来。此外,第一个字符不能为数字,字符串开头不能是连字符 (-) 后跟数字或连字符。

为避免歧义,各个属性对应的<custom-ident> 禁止使用以下特殊值:

animation-name

禁用 CSS 关键字 unset, initial, inherit, none

counter-resetcounter-increment

禁止使用unset, initial, inherit, none.

@counter-stylelist-style-type

禁止使用unset, initial, inherit, none, inline, outside. 同时不同浏览器预定义的值如:disc, circle, square, decimal, cjk-decimal, decimal-leading-zero, lower-roman, upper-roman, lower-greek, lower-alpha, lower-latin, upper-alpha, upper-latin, arabic-indic, armenian, bengali, cambodian, cjk-earthly-branch, cjk-heavenly-stem, cjk-ideographic, devanagari, ethiopic-numeric, georgian, gujarati, gurmukhi, hebrew, hiragana, hiragana-iroha, japanese-formal, japanese-informal, kannada, katakana, katakana-iroha, khmer, korean-hangul-formal, korean-hanja-formal, korean-hanja-informal, lao, lower-armenian, malayalam, mongolian, myanmar, oriya, persian, simp-chinese-formal, simp-chinese-informal, tamil, telugu, thai, tibetan, trad-chinese-formal, trad-chinese-informal, upper-armenian, disclosure-open, 和 disclosure-close也不能使用。

grid-row-start (en-US) grid-row-end (en-US) grid-column-start (en-US) grid-column-end (en-US)

禁止使用 span

will-change

禁止使用unset, initial, inherit, 以及 will-change, auto, scroll-position, and contents.

示例

有效标识符

nono79            字母数字混合
ground-level      字母 - 字母
-test             连字符后跟字母
_internal         下划线后跟字母
\22 toto          Unicode 编码后跟字母
bili\.bob         转义的句号

无效标识符

34rem             第一个字符不能是数字
-12rad            第一个字符连字符后不能跟数字
bili.bob          只有字母数字、连字符-、下划线_不需要转义
--toto            第一个字符不能为连字符后跟连字符
'bilibob'         不能用单引号包起来,这是一个字符串类型
"bilibob"         不能用双引号包起来,这是一个字符串类型

规范

Specification
CSS Values and Units Module Level 4
# custom-idents
CSS Will Change Module Level 1
# valdef-will-change-custom-ident
CSS Counter Styles Level 3
# typedef-counter-style-name
CSS Lists and Counters Module Level 3
# counter-properties

浏览器兼容性

由于这种类型不是真正的类型,而是用于简化允许值描述的便利类型,因此没有浏览器兼容性信息。