--- title: セレクターリスト slug: Web/CSS/Selector_list tags: - CSS - Selector - Selector Lists - Selectors translation_of: Web/CSS/Selector_list --- <div>{{CSSRef}}</div> <p>CSS の <ruby><strong>セレクターリスト</strong><rp> (</rp><rt>selector list</rt><rp>)</rp></ruby> (<code>,</code>) は,すべての一致するノードを選択します。</p> <pre class="brush: css no-line-numbers notranslate">/* すべての一致する要素を選択 */ span, div { border: red 2px solid; }</pre> <p>スタイルシートの大きさを縮小するために、グループセレクターをカンマ区切りのリストにすることができます。</p> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="syntaxbox notranslate">element, element, element { <em>style properties</em> }</pre> <h2 id="事例">事例</h2> <h3 id="Single_Line_Grouping" name="Single_Line_Grouping">単一行のグループ化</h3> <p>カンマ区切りのリストを使用して単一行にしたグループ化セレクターです。</p> <pre class="brush: css notranslate">h1, h2, h3, h4, h5, h6 { font-family: helvetica; } </pre> <h3 id="Multi_Line_Grouping" name="Multi_Line_Grouping">複数行のグループ化</h3> <p>カンマ区切りのリストを使用して複数行にしたグループ化セレクターです。</p> <pre class="brush: css notranslate">#main, .content, article { font-size: 1.1em; } </pre> <h3 id="Selector_list_invalidation" name="Selector_list_invalidation">セレクターリストの無効化</h3> <p>セレクターリストを使用する欠点は、以下のものが等価ではないことです。</p> <pre class="brush: css notranslate">h1 { font-family: sans-serif } h2:maybe-unsupported { font-family: sans-serif } h3 { font-family: sans-serif }</pre> <pre class="brush: css notranslate">h1, h2:maybe-unsupported, h3 { font-family: sans-serif }</pre> <p>これは、セレクターリスト内に未対応のセレクターが一つでもあった場合は、規則全体が無効化されてしまうためです。</p> <p>この対策方法としては、 {{CSSxRef(":is", ":is()")}} セレクターを使用すれば、単純に引数内の無効なセレクターを無視しますが、 {{CSSxRef(":is", ":is()")}} の詳細度の計算方法の影響で、すべてのセレクターの重みが同じ詳細度になります。</p> <pre class="brush: css notranslate">h1 { font-family: sans-serif } h2:maybe-unsupported { font-family: sans-serif } h3 { font-family: sans-serif }</pre> <pre class="brush: css notranslate">:is(h1, h2:maybe-unsupported, h3) { font-family: sans-serif }</pre> <h2 id="Specifications" name="Specifications">仕様書</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> <th scope="col">状態</th> <th scope="col">備考</th> </tr> </thead> <tbody> <tr> <td>{{SpecName("CSS4 Selectors", "#grouping", "Selector Lists")}}</td> <td>{{Spec2("CSS4 Selectors")}}</td> <td>「セレクターリスト」に改名</td> </tr> <tr> <td>{{SpecName('CSS1', '#grouping', 'grouping')}}</td> <td>{{Spec2('CSS1')}}</td> <td>初回定義</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> <div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> <p>{{Compat("css.selectors.list")}}</p> <h2 id="See_also" name="See_also">関連情報</h2> <ul> <li>The {{CSSxRef(":is", ":is()")}} {{Experimental_Inline}} および {{CSSxRef(":where", ":where()")}} {{Experimental_Inline}} 擬似クラスは、セレクターリストの無効化の古い間違いを起こしません。</li> </ul>