首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

字符串 | <string>

<string>CSS数据类型表示一串字符序列。字符串在众多的CSS属性所使用,包括contentfont-familyquotes

语法

一个字符串由一个或多个由double(")或single(')引号包围的Unicode字符组成。

大多数字符可以直接使用字面值。当用反斜线转义时,它们也可以用各自的十六进制的Unicode编码点表示。例如,\27表示单引号('),\A9表示版权符号(?)。

重要的是,某些本来是无效的字符可以用反斜线(\)来转义。这些包括在双引号字符串中使用双引号,单引号字符串中使用单引号和反斜杠本身。

除非用换行符(如\A\00000A)转义,否则新行是无效的。但是,在你的代码中,字符串可以跨越多行,在这种情况下,每一行都必须用"\"作为行的最后一个字符来转义。

实例

代码语言:javascript
复制
/* 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)

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com