CSS参考手册
值和单位 | Values & Units
字符串 |
<string>
CSS数据类型表示一串字符序列。字符串在众多的CSS属性所使用,包括content
,font-family
和quotes
。
语法
一个字符串由一个或多个由double("
)或single('
)引号包围的Unicode字符组成。
大多数字符可以直接使用字面值。当用反斜线转义时,它们也可以用各自的十六进制的Unicode编码点表示。例如,\27
表示单引号('
),\A9
表示版权符号(©)。
重要的是,某些本来是无效的字符可以用反斜线(\
)来转义。这些包括在双引号字符串中使用双引号,单引号字符串中使用单引号和反斜杠本身。
除非用换行符(如\A
或\00000A
)转义,否则新行是无效的。但是,在你的代码中,字符串可以跨越多行,在这种情况下,每一行都必须用"\"
作为行的最后一个字符来转义。
实例
/* Simple quote escaping */
"Awesome string with double quotes"
"Awesome string with \" escaped double quotes"
'Awesome string with single quotes'
"Awesome string with \' escaped single quotes"
/* New line in a string */
"Awesome string with \Aline break"
/* String spanning over two lines (these two strings are exactly the same) */
"A really long \
awesome string"
"A really long awesome string"
注意:双引号字符串也可以使用使用\22
来转义,单引号字符串可以使用\27
来转义。
规范
Specification |
Status |
Comment |
---|---|---|
CSS Values and Units Module Level 3The definition of '<string>' in that specification. |
Candidate Recommendation |
No significant change from CSS Level 2 (Revision 1). |
CSS Level 2 (Revision 1)The definition of '<string>' in that specification. |
Recommendation |
Explicit definition; allows 6-digit Unicode escaped characters. |
CSS Level 1The definition of '<string>' in that specification. |
Recommendation |
Implicit definition; allows 4-digit Unicode escaped characters. |
浏览器兼容性
Feature |
Chrome |
Firefox (Gecko) |
Internet Explorer |
Opera |
Safari |
---|---|---|---|---|---|
Basic support |
1.0 |
1.0 (1.0) |
(Yes) |
(Yes) |
1.0 (85) |
\xx |
1.0 |
1.0 (1.0) |
6.0 |
(Yes) |
1.0 (85) |
Feature |
Android |
Chrome for Android |
Firefox Mobile (Gecko) |
IE Mobile |
Opera Mobile |
Safari Mobile |
---|---|---|---|---|---|---|
Basic support |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
\xx |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
(Yes) |
值和单位 | Values & Units相关

层叠样式表( Cascading Style Sheets )是一种用来表现 HTML 或 XML 等文件样式的计算机语言。CSS 不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。