語法
<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),以及以下值:noneinlineoutside
此外,許多預定義值由不同的瀏覽器實現:
disccirclesquaredecimalcjk-decimaldecimal-leading-zerolower-romanupper-romanlower-greeklower-alphalower-latinupper-alphaupper-latinarabic-indicarmenianbengalicambodiancjk-earthly-branchcjk-heavenly-stemcjk-ideographicdevanagariethiopic-numericgeorgiangujaratigurmukhihebrewhiraganahiragana-irohajapanese-formaljapanese-informalkannadakatakanakatakana-irohakhmerkorean-hangul-formalkorean-hanja-formalkorean-hanja-informallaolower-armenianmalayalammongolianmyanmaroriyapersiansimp-chinese-formalsimp-chinese-informaltamilteluguthaitibetantrad-chinese-formaltrad-chinese-informalupper-armeniandisclosure-opendisclosure-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 |
瀏覽器相容性
由於此型別不是真實型別,而是用於簡化允許值描述的便利型別,因此沒有此類瀏覽器相容性資訊。