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/ja/web/css/class_selectors/index.html | 107 ++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 files/ja/web/css/class_selectors/index.html (limited to 'files/ja/web/css/class_selectors') diff --git a/files/ja/web/css/class_selectors/index.html b/files/ja/web/css/class_selectors/index.html new file mode 100644 index 0000000000..f5acf09c25 --- /dev/null +++ b/files/ja/web/css/class_selectors/index.html @@ -0,0 +1,107 @@ +--- +title: クラスセレクター +slug: Web/CSS/Class_selectors +tags: + - CSS + - Reference + - セレクター +translation_of: Web/CSS/Class_selectors +--- +
{{CSSRef}}
+ +

CSSクラスセレクター (class selector) は、 {{htmlattrxref("class")}} 属性の内容に基づいて要素を選択します。

+ +
/* class="spacious" であるすべての要素 */
+.spacious {
+  margin: 2em;
+}
+
+/* class="spacious" であるすべての <li> 要素 */
+li.spacious {
+  margin: 2em;
+}
+
+/* "spacious" および "elegant" の両方をクラスリストに含む <li> 要素すべて */
+/* 例えば、 class="elegant retro spacious" */
+li.spacious.elegant {
+  margin: 2em;
+}
+
+ +

構文

+ +
.クラス名 { スタイルプロパティ }
+ +

なお、これは以下の{{Cssxref("Attribute_selectors", "属性セレクター")}}と等価です。

+ +
[class~=クラス名] { スタイルプロパティ }
+ +

+ +

CSS

+ +
.red {
+  color: #f33;
+}
+
+.yellow-bg {
+  background: #ffa;
+}
+
+.fancy {
+  font-weight: bold;
+  text-shadow: 4px 4px 3px #77f;
+}
+
+ +

HTML

+ +
<p class="red">この段落は赤い文字です。</p>
+<p class="red yellow-bg">この段落は黄色の背景に赤い文字です。</p>
+<p class="red fancy">この段落は「fancy」スタイルで赤い文字です。</p>
+<p>これは単なる普通の段落です。</p>
+
+ +

結果

+ +

{{EmbedLiveSample('Example')}}

+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
仕様状態コメント
{{SpecName('CSS4 Selectors', '#class-html', 'class selectors')}}{{Spec2('CSS4 Selectors')}}変更なし
{{SpecName('CSS3 Selectors', '#class-html', 'class selectors')}}{{Spec2('CSS3 Selectors')}} 
{{SpecName('CSS2.1', 'selector.html#class-html', 'child selectors')}}{{Spec2('CSS2.1')}} 
{{SpecName('CSS1', '#class-as-selector', 'child selectors')}}{{Spec2('CSS1')}}初回定義
+ +

ブラウザー実装状況

+ + + +

{{Compat("css.selectors.class")}}

-- cgit v1.2.3-54-g00ecf