语法
<custom-ident>
的语法类似于 CSS 标识符(例如属性名称),但它区分大小写。它由一个或多个字符组成,字符可以是以下任意一种:
- 任意字母字符(
A
到Z
,或a
到z
), - 任意十进制数字(
0
到9
), - 连字符(
-
), - 下划线(
_
), - 转义字符(前面带有反斜杠,
\
), - Unicode 字符(格式为反斜杠
\
,后跟一到六个十六进制数字,表示其 Unicode 码点)
请注意,id1
、Id1
、iD1
和 ID1
都是不同的标识符,因为它们区分大小写。
转义字符
任何 Unicode 码点都可以通过转义作为 <custom-ident>
或带引号的 <string>
的一部分。
在 CSS 中,有几种方法可以转义字符。转义序列以反斜杠(\
)开头,后跟:
- 一到六个十六进制(
ABCDEF0123456789
)数字。十六进制数字可以选择后跟空白。十六进制转义序列被替换为由这些数字给出的值的 Unicode 码点。空白允许序列后跟实际的十六进制数字(而不是被替换的数字)。 - 任何不是十六进制数字或换行符的 Unicode 码点。
示例
- "&B" 可以写成
\26 B
或\000026B
。 - "hi.there" 可以写成
hi\.there
或hi\002Ethere
。 - "toto?" 可以写成
toto\?
、toto\3F
或toto\00003F
。
要在转义序列后包含实际的空白,请在转义序列中包含两个空白。
禁用值
<custom-ident>
不得放在单引号或双引号之间,因为这会与 <string>
相同。此外,第一个字符不得是十进制数字,也不得是后跟十进制数字的连字符(-
)。
为了防止歧义,每个使用 <custom-ident>
的属性都禁止使用特定值。
animation-name
-
禁止全局 CSS 值(
unset
、initial
和inherit
),以及none
。 counter-reset
、counter-increment
-
禁止全局 CSS 值(
unset
、initial
和inherit
),以及none
。 @counter-style
、list-style-type
-
禁止全局 CSS 值(
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
、grid-row-end
、grid-column-start
、grid-column-end
、grid-template-rows
、grid-template-columns
-
禁止
span
和auto
值。 view-transition-name
-
禁止全局 CSS 值(
unset
、initial
和inherit
),以及none
。 will-change
-
禁止全局 CSS 值(
unset
、initial
和inherit
),以及will-change
、auto
、scroll-position
和contents
值。
示例
有效标识符
nono79 A mix of alphanumeric characters and numbers ground-level A mix of alphanumeric characters and a dash -test A dash followed by alphanumeric characters _internal An underscore followed by alphanumeric characters \22 toto A Unicode character followed by a sequence of alphanumeric characters scooby\.doo A correctly escaped period
无效标识符
34rem It must not start with a decimal digit. -12rad It must not start with a dash followed by a decimal digit. scooby.doo Only alphanumeric characters, _, and - needn't be escaped. 'scoobyDoo' This would be a <string>. "scoobyDoo" This would be a <string>.
规范
规范 |
---|
CSS 值和单位模块第 4 级 # custom-idents |
CSS Will Change Module Level 1 # valdef-will-change-custom-ident |
CSS Counter Styles Level 3 # typedef-counter-style-name |
CSS 列表与计数器模块第 3 级 # counter-properties |
浏览器兼容性
由于此类型不是真实类型,而是用于简化允许值描述的便利类型,因此没有此类浏览器兼容性信息。