From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/css/string/index.html | 142 ++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 files/zh-cn/web/css/string/index.html (limited to 'files/zh-cn/web/css/string/index.html') diff --git a/files/zh-cn/web/css/string/index.html b/files/zh-cn/web/css/string/index.html new file mode 100644 index 0000000000..01a13db60b --- /dev/null +++ b/files/zh-cn/web/css/string/index.html @@ -0,0 +1,142 @@ +--- +title: +slug: Web/CSS/string +translation_of: Web/CSS/string +--- +
{{CSSRef}}
+ +
在CSS中,<string> 是用来表示一串字符的数据类型,它被用在众多CSS属性中,例如{{cssxref("content")}}、{{cssxref("font-family")}}、和{{cssxref("quotes")}}。
+ +

使用规则

+ +

<string> 数据类型是由包含在英文双引号(")或英文单引号(')中的任意数量的Unicode字符组成。

+ +

大多数字符都可以写成字面量的形式,并且所有字符都可以写成以反斜线(\)开头的十六进制Unicode码点的形式。比如说:\22表示一个双引号,\27表示一个单引号,\A9表示版权声明符号(©)。

+ +

需要注意的是,在使用某些特殊字符时需要在前面加上反斜线来转义,包括但不限于在双引号字符串中使用双引号字符,在单引号字符串中使用单引号字符,以及反斜线字符,比如\\表示一个反斜线字符。

+ +

当你想换行的时候,必须使用像\A或者\00000A这样的换行符。不过在你的代码中,可以通过在每行末尾增加一个反斜线(\)的方式来创建一个多行的字符串。

+ +
+

注意: CSS<string>中不能使用像&nbsp;或者&#8212;这样的实体。

+
+ +

例子

+ +
/* Simple strings */
+"This string is demarkated by double quotes."
+'This string is demarkated 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"
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('CSS3 Values', '#strings', '<string>')}}{{Spec2('CSS3 Values')}}No significant change from CSS Level 2 (Revision 1).
{{SpecName('CSS2.1', 'syndata.html#strings', '<string>')}}{{Spec2('CSS2.1')}}Explicit definition; allows 6-digit Unicode escaped characters.
{{SpecName('CSS1', '', '<string>')}}{{Spec2('CSS1')}}Implicit definition; allows 4-digit Unicode escaped characters.
+ +

浏览器兼容性

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support1.01.0 (1.0){{CompatVersionUnknown}}{{compatVersionUnknown}}1.0 (85)
\xx1.01.0 (1.0)6.0{{compatVersionUnknown}}1.0 (85)
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{compatVersionUnknown}}{{compatVersionUnknown}}{{compatVersionUnknown}}{{compatVersionUnknown}}{{compatVersionUnknown}}{{compatVersionUnknown}}
\xx{{compatVersionUnknown}}{{compatVersionUnknown}}{{compatVersionUnknown}}{{compatVersionUnknown}}{{compatVersionUnknown}}{{compatVersionUnknown}}
+
-- cgit v1.2.3-54-g00ecf