<string>
CSS
data type
represents a sequence of characters. Strings are used in numerous CSS properties, such as
content
,
font-family
,和
quotes
.
<string>
data type is composed of any number of
Unicode
characters surrounded by either double (
"
) or single (
'
) quotes.
Most characters can be represented literally. All characters can also be represented with their respective
Unicode code points
in hexadecimal, in which case they are preceded by a backslash (
\
). For example,
\22
represents a double quote,
\27
a single quote (
'
), and
\A9
the copyright symbol (
©
).
Importantly, certain characters which would otherwise be invalid can be escaped with a backslash. These include double quotes when used inside a double-quoted string, single quotes when used inside a single-quoted string, and the backslash itself. For example,
\\
will create a single backslash.
To output new lines, you must escape them with a line feed character such as
\A
or
\00000A
. In your code, however, strings can span multiple lines, in which case each new line must be escaped with a
\
as the last character of the line.
However, to get new lines, you must also set the
white-space
property to appropriate value.
注意:
HTML entities
(譬如
or
—
) cannot be used in a CSS
<string>
.
/* Simple 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 Values and Units Module Level 3
The definition of '<string>' in that specification. |
候选推荐 | No significant change from CSS Level 2 (Revision 1). |
|
CSS Level 2 (Revision 1)
The definition of '<string>' in that specification. |
推荐 | Explicit definition; allows 6-digit Unicode escaped characters. |
|
CSS Level 1
The definition of '<string>' in that specification. |
推荐 | Implicit definition; allows 4-digit Unicode escaped characters. |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| <string> | Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 3 | Opera 完整支持 3.5 | Safari 完整支持 1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
Unicode escaped characters (
\xx
)
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 6 | Opera 完整支持 7 | Safari 完整支持 1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
完整支持
<angle-percentage>
<angle>
<basic-shape>
<blend-mode>
<custom-ident>
<dimension>
<frequency-percentage>
<frequency>
<gradient>
<image>
<integer>
<length-percentage>
<length>
<number>
<percentage>
<ratio>
<resolution>
<shape>
<string>
<time-percentage>
<time>
<transform-function>
<url>
color
flex
ident
position