From 35918176145e2f9de541ac623706cd3ced71612d Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Sun, 21 Nov 2021 17:30:52 +0900 Subject: CSS Values and Units の文書を更新 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 2021/11/19 時点の英語版に同期 --- files/ja/web/css/string/index.md | 145 +++++++++++++++------------------------ 1 file changed, 57 insertions(+), 88 deletions(-) (limited to 'files/ja/web/css/string') diff --git a/files/ja/web/css/string/index.md b/files/ja/web/css/string/index.md index 80290bbea9..ba0bd8d1ee 100644 --- a/files/ja/web/css/string/index.md +++ b/files/ja/web/css/string/index.md @@ -4,94 +4,63 @@ slug: Web/CSS/string tags: - CSS - CSS データ型 - - CSS Data Type - - Data Type - - Layout - - Reference - - Web - - ウェブ + - データ型 - レイアウト + - リファレンス + - ウェブ translation_of: Web/CSS/string --- -
{{CSSRef}}
- -

<string>CSSデータ型で、一連の文字列を表します。文字列は {{CSSxRef("content")}}, {{CSSxRef("font-family")}}, {{CSSxRef("quotes")}} など、数々の CSS プロパティで使用されます。

- -

構文

- -

<string> データ型は任意の数の Unicode 文字を、二重引用符 (") または単一引用符 (') で囲んで構成します。

- -

多くの文字は文字通りに表現されます。またすべての文字は、それぞれの 16 進数の Unicode コードポイントで表現することもできます。例えば、 \22 は二重引用符を表し、 \27 は単一引用符 (')、 \A9 は著作権記号 (©) を表します。

- -

重要なことは、文字によっては他の方法として、バックスラッシュでエスケープすることもできます。これらには二重引用符で囲まれた文字列内で使われる二重引用符、単一引用符で囲まれた文字列内で使われる単一引用符、およびバックスラッシュ自身です。例えば、 \\ は単一のバックスラッシュを生成します。

- -

改行文字を出力するには、 \A 又は \00000A のように改行文字としてエスケープする必要があります。しかし、改行を行の末尾の文字として \ でエスケープすると、コード内で文字列を複数行に渡らせることができます。

- -
-

注: HTML エンティティ (&nbsp;&#8212; など) は、 CSS の <string> の中で使用することはできません。

-
- -

- -

有効な文字列の例

- -
/* 単純な文字列 */
-"This string is demarcated by double quotes."
-'This string is demarcated by single quotes.'
-
-/* 文字のエスケープ */
-"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."
-
-/* 文字列内の改行 */
-"This string has a \Aline break in it."
-
-/* 2 行にわたる文字列 (これら 2 つの文字列は同じ出力になります) */
-"A really long \
-awesome string"
-"A really long awesome string"
-
- -

仕様書

- - - - - - - - - - - - - - - - - - - - - - - - - - -
仕様書状態備考
{{SpecName('CSS3 Values', '#strings', '<string>')}}{{Spec2('CSS3 Values')}}CSS Level 2 (Revision 1) から重要な変更なし
{{SpecName('CSS2.1', 'syndata.html#strings', '<string>')}}{{Spec2('CSS2.1')}}明示的定義; Unicode の 6 桁エスケープ文字を許容
{{SpecName('CSS1', '', '<string>')}}{{Spec2('CSS1')}}暗黙的定義; Unicode の 4 桁エスケープ文字を許容
- -

ブラウザーの互換性

- -

{{Compat("css.types.string")}}

- -

関連情報

- - +{{CSSRef}} + +**``** は [CSS](/ja/docs/Web/CSS) の[データ型](/ja/docs/Web/CSS/CSS_Types)で、一連の文字列を表します。文字列は {{CSSxRef("content")}}, {{CSSxRef("font-family")}}, {{CSSxRef("quotes")}} など、数々の CSS プロパティで使用されます。 + +## 構文 + +`` データ型は任意の数の [Unicode](https://ja.wikipedia.org/wiki/Unicode) 文字を、二重引用符 (`"`) または単一引用符 (`'`) で囲んで構成します。 + +多くの文字は文字通りに表現されます。またすべての文字は、それぞれの 16 進数の [Unicode コードポイント](https://ja.wikipedia.org/wiki/Unicode#Code_point_planes_and_blocks)で表現することもできます。例えば、 `\22` は二重引用符を表し、 `\27` は単一引用符 (`'`)、 `\A9` は著作権記号 (`©`) を表します。 + +重要なことは、文字によっては他の方法として、バックスラッシュでエスケープすることもできます。これらには二重引用符で囲まれた文字列内で使われる二重引用符、単一引用符で囲まれた文字列内で使われる単一引用符、およびバックスラッシュ自身です。例えば、 `\\` は単一のバックスラッシュを生成します。 + +改行文字を出力するには、 `\A` または `\00000A` のように改行文字としてエスケープする必要があります。しかし、改行を行の末尾の文字として `\` でエスケープすると、コード内で文字列を複数行に渡らせることができます。 + +ただし、改行を行うためには、{{cssxref("white-space")}} プロパティに適切な値を設定する必要があります。 + +> **Note:** [HTML エンティティ](/ja/docs/Glossary/Entity) (` ` や `—` など) は、 CSS の `` の中で使用することはできません。 + +## 例 + +### 有効な文字列の例 + + /* 単純な文字列 */ + "This string is demarcated by double quotes." + 'This string is demarcated by single quotes.' + + /* 文字のエスケープ */ + "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." + + /* 文字列内の改行 */ + "This string has a \Aline break in it." + + /* 2 行にわたる文字列 (これら 2 つの文字列は同じ出力になります) */ + "A really long \ + awesome string" + "A really long awesome string" + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- [CSS の単位と値](/ja/docs/Web/CSS/CSS_Values_and_Units) +- [CSS の基本データ型](/ja/docs/Web/CSS/CSS_Types) +- [CSS 入門: 単位と値](/ja/docs/Learn/CSS/Building_blocks/Values_and_units) -- cgit v1.2.3-54-g00ecf