<custom-ident>

<custom-ident> CSS 資料型別表示用作識別符號的任意使用者定義字串。它區分大小寫,並且在各種上下文中禁止某些值以防止歧義。

語法

<custom-ident> 的語法類似於 CSS 識別符號(例如屬性名稱),但它區分大小寫。它由一個或多個字元組成,字元可以是以下任意一種:

  • 任意字母字元(AZ,或 az),
  • 任意十進位制數字(09),
  • 連字元(-),
  • 下劃線(_),
  • 跳脫字元(前面帶有反斜槓,\),
  • Unicode 字元(格式為反斜槓 \,後跟一到六個十六進位制數字,表示其 Unicode 碼點)

請注意,id1Id1iD1ID1 都是不同的識別符號,因為它們區分大小寫

跳脫字元

任何 Unicode 碼點都可以透過轉義作為 <custom-ident> 或帶引號的 <string> 的一部分。

在 CSS 中,有幾種方法可以跳脫字元。轉義序列以反斜槓(\)開頭,後跟:

  • 一到六個十六進位制(ABCDEF0123456789)數字。十六進位制數字可以選擇後跟空白。十六進位制轉義序列被替換為由這些數字給出的值的 Unicode 碼點。空白允許序列後跟實際的十六進位制數字(而不是被替換的數字)。
  • 任何不是十六進位制數字或換行符的 Unicode 碼點。

示例

  • "&B" 可以寫成 \26 B\000026B
  • "hi.there" 可以寫成 hi\.therehi\002Ethere
  • "toto?" 可以寫成 toto\?toto\3Ftoto\00003F

要在轉義序列後包含實際的空白,請在轉義序列中包含兩個空白。

停用值

<custom-ident> 不得放在單引號或雙引號之間,因為這會與 <string> 相同。此外,第一個字元不得是十進位制數字,也不得是後跟十進位制數字的連字元(-)。

為了防止歧義,每個使用 <custom-ident> 的屬性都禁止使用特定值。

animation-name

禁止全域性 CSS 值(unsetinitialinherit),以及 none

counter-resetcounter-increment

禁止全域性 CSS 值(unsetinitialinherit),以及 none

@counter-stylelist-style-type

禁止全域性 CSS 值(unsetinitialinherit),以及以下值:

  • 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-startgrid-row-endgrid-column-startgrid-column-endgrid-template-rowsgrid-template-columns

禁止 spanauto 值。

view-transition-name

禁止全域性 CSS 值(unsetinitialinherit),以及 none

will-change

禁止全域性 CSS 值(unsetinitialinherit),以及 will-changeautoscroll-positioncontents 值。

示例

有效識別符號

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

瀏覽器相容性

由於此型別不是真實型別,而是用於簡化允許值描述的便利型別,因此沒有此類瀏覽器相容性資訊。

另見