diff options
Diffstat (limited to 'files/ja/web/css/_doublecolon_slotted')
| -rw-r--r-- | files/ja/web/css/_doublecolon_slotted/index.html | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/files/ja/web/css/_doublecolon_slotted/index.html b/files/ja/web/css/_doublecolon_slotted/index.html new file mode 100644 index 0000000000..e02c142be6 --- /dev/null +++ b/files/ja/web/css/_doublecolon_slotted/index.html @@ -0,0 +1,113 @@ +--- +title: '::slotted()' +slug: 'Web/CSS/::slotted' +tags: + - '::slotted' + - CSS + - Reference + - ウェブ + - レイアウト + - 疑似要素 +translation_of: 'Web/CSS/::slotted' +--- +<div>{{ CSSRef }}</div> + +<p><strong><code>::slotted()</code></strong> は <a href="/ja/docs/Web/CSS">CSS</a> の <a href="/ja/docs/Web/CSS/Pseudo-elements">疑似要素</a>で、 HTML テンプレート内にあるスロットに配置された任意の要素を表します (詳しくは<a href="/ja/docs/Web/Web_Components/Using_templates_and_slots">テンプレートとスロットの利用</a>をご覧ください)。</p> + +<p>これは <a href="/ja/docs/Web/Web_Components/Using_shadow_DOM">shadow DOM</a> 内に配置された CSS の中で使われた時のみ機能します。なお、このセレクターはスロット内に配置されたテキストノードは選択しません。実際の要素のみを対象にします。</p> + +<pre class="brush: css no-line-numbers">/* スロット内に配置された任意の要素を選択 */ +::slotted(*) { + font-weight: bold; +} + +/* スロット内に配置された <span> 要素を選択 */ +::slotted(span) { + font-weight: bold; +} +</pre> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox">{{csssyntax}}</pre> + +<h2 id="Examples" name="Examples">例</h2> + +<p>以下のコードの断片は <a href="https://github.com/mdn/web-components-examples/tree/master/slotted-pseudo-element">slotted-pseudo-element</a> デモから取られたものです (<a href="https://mdn.github.io/web-components-examples/slotted-pseudo-element/">ライブでもご覧ください</a>)。</p> + +<p>このデモでは、3つのスロットを持つ単純なテンプレートを使用します。</p> + +<pre class="brush: html"><template id="person-template"> + <div> + <h2>Personal ID Card</h2> + <slot name="person-name">NAME MISSING</slot> + <ul> + <li><slot name="person-age">AGE MISSING</slot></li> + <li><slot name="person-occupation">OCCUPATION MISSING</slot></li> + </ul> + </div> +</template></pre> + +<p>カスタム要素 — <code><person-details></code> — は以下のように定義されています。</p> + +<pre class="brush: js">customElements.define('person-details', + class extends HTMLElement { + constructor() { + super(); + let template = document.getElementById('person-template'); + let templateContent = template.content; + + const shadowRoot = this.attachShadow({mode: 'open'}); + + let style = document.createElement('style'); + style.textContent = 'div { padding: 10px; border: 1px solid gray; width: 200px; margin: 10px; }' + + 'h2 { margin: 0 0 10px; }' + + 'ul { margin: 0; }' + + 'p { margin: 10px 0; }' + + '::slotted(*) { color: gray; font-family: sans-serif; } '; + + shadowRoot.appendChild(style); + shadowRoot.appendChild(templateContent.cloneNode(true)); + } +})</pre> + +<p><code>style</code> 要素のコンテンツを埋めると、スロットになるすべての要素を選択し (<code>::slotted(*)</code>)、それぞれに異なるフォントと色を与えているのが分かるでしょう。これにより、隣のコンテンツが埋まらなかったスロットよりも目立たせることができます。</p> + +<p>この要素がページに挿入されると、以下のように見えます。</p> + +<pre class="brush: html"><person-details> + <p slot="person-name">Dr. Shazaam</p> + <span slot="person-age">Immortal</span> + <span slot="person-occupation">Superhero</span> +</person-details></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('CSS Scope', '#slotted-pseudo', '::slotted') }}</td> + <td>{{ Spec2('CSS Scope') }}</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.slotted")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="/ja/docs/Web/Web_Components">Web components</a></li> +</ul> |
