語法
<string> 資料型別由任意數量的 Unicode 字元組成,這些字元用雙引號 (") 或單引號 (') 括起來。
大多數字符都可以直接表示。所有字元也可以用它們各自的十六進位制 Unicode 碼點表示,在這種情況下,它們前面有一個反斜槓 (\)。例如,\22 表示雙引號,\27 表示單引號 ('),\A9 表示版權符號 (©)。
重要的是,某些原本無效的字元可以用反斜槓進行轉義。這些字元包括在雙引號字串中使用的雙引號、在單引號字串中使用的單引號以及反斜槓本身。例如,\\ 將建立一個反斜槓。
要輸出換行符,必須使用換行符字元(如 \A 或 \00000A)對其進行轉義。然而,在您的程式碼中,字串可以跨多行,在這種情況下,每行的新行都必須用 \ 作為行的最後一個字元進行轉義。
但是,要獲得換行符,您還必須將 white-space 屬性設定為適當的值。
注意: 字元引用(如 或 —)不能在 CSS <string> 中使用。
示例
有效字串的示例
css
/* Basic strings */
"This string is demarcated by double quotes."
'This string is demarcated by single quotes.'
/* Character escaping */
"This is a string with \" an escaped double quote."
"This string also has \22 an escaped double quote."
'This is a string with \' an escaped single quote.'
'This string also has \27 an escaped single quote.'
"This is a string with \\ an escaped backslash."
/* New line in a string */
"This string has a \Aline break in it."
/* String spanning two lines of code (these two strings will have identical output) */
"A really long \
awesome string"
"A really long awesome string"
規範
| 規範 |
|---|
| CSS 值和單位模組第 4 級 # 字串 |
瀏覽器相容性
載入中…