diff options
| author | Masahiro FUJIMOTO <mfujimot@gmail.com> | 2022-01-19 01:16:32 +0900 |
|---|---|---|
| committer | Masahiro FUJIMOTO <mfujimot@gmail.com> | 2022-01-26 08:56:49 +0900 |
| commit | 96e7dc4c05c6e47c41088f38bfd6d216fc694df5 (patch) | |
| tree | 4fbe7f5aec9ef8df3e78e0f99871dc66b7a83cc2 /files/ja/web/css/_colon_host-context()/index.html | |
| parent | 8123b421cb3a943894500e6e5d7caa15a6aea9cd (diff) | |
| download | translated-content-96e7dc4c05c6e47c41088f38bfd6d216fc694df5.tar.gz translated-content-96e7dc4c05c6e47c41088f38bfd6d216fc694df5.tar.bz2 translated-content-96e7dc4c05c6e47c41088f38bfd6d216fc694df5.zip | |
Web/CSS/:host-context() を移行
Diffstat (limited to 'files/ja/web/css/_colon_host-context()/index.html')
| -rw-r--r-- | files/ja/web/css/_colon_host-context()/index.html | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/files/ja/web/css/_colon_host-context()/index.html b/files/ja/web/css/_colon_host-context()/index.html deleted file mode 100644 index cd6c5f9b94..0000000000 --- a/files/ja/web/css/_colon_host-context()/index.html +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: ':host-context()' -slug: 'Web/CSS/:host-context()' -tags: - - ':host-context()' - - CSS - - Experimental - - Layout - - Pseudo-class - - Reference - - Selector - - Web -translation_of: 'Web/CSS/:host-context()' ---- -<div>{{CSSRef}}</div> - -<p><span class="seoSummary"><strong><code>:host-context()</code></strong> は <a href="/ja/docs/Web/CSS">CSS</a> の<a href="/ja/docs/Web/CSS/Pseudo-classes">擬似クラス</a>関数で、内部で使用される CSS を含む<a href="/ja/docs/Web/Web_Components/Using_shadow_DOM">シャドウ DOM</a> のシャドウホストを選択します (そのため、シャドウ DOM の中のカスタム要素を選択することができます)。 — しかし、関数の引数として与えられたセレクターがシャドウホストの祖先に一致した場合のみです。</span></p> - -<p><span class="seoSummary">言い換えれば、これによってカスタム要素やそのカスタム要素のシャドウ DOM 内のものは、外部 DOM 内の位置や、祖先要素に適用されたクラスや属性に基づいて、異なるスタイルを適用することができます。</span></p> - -<p>典型的な使い方としては、子孫のセレクター式 (例えば <code>h1</code>) を使って、 <code><h1></code> の中にあるカスタム要素のインスタンスのみを選択することができます。もう一つの典型的な使用法は、内部要素が任意の子孫要素のクラスや属性に反応するようにすることです。例えば、 <code>.dark-theme</code> クラスが <code><body></code> に適用されたときに、異なるテキスト色を適用することができます。</p> - -<div class="note"> -<p><strong>注</strong>: これはシャドウ DOM の外で使用した場合、効果がありません。</p> -</div> - -<pre class="brush: css no-line-numbers notranslate">/* Selects a shadow root host, only if it is - a descendant of the selector argument given */ -:host-context(h1) { - font-weight: bold; -} - -:host-context(main article) { - font-weight: bold; -} - -/* Changes paragraph text color from black to white when - a .dark-theme class is applied to the document body */ -p { - color: #000; -} - -:host-context(body.dark-theme) p { - color: #fff; -} -</pre> - -<h2 id="Syntax" name="Syntax">構文</h2> - -{{CSSSyntax}} - -<h2 id="Examples" name="Examples">例</h2> - -<h3 id="Selectively_styling_shadow_hosts" name="Selectively_styling_shadow_hosts">シャドウホストの選択的なスタイル付け</h3> - -<p>以下のスニペットは <a href="https://github.com/mdn/web-components-examples/tree/master/host-selectors">host-selectors example</a> から取ったものです。 (<a href="https://mdn.github.io/web-components-examples/host-selectors/">ライブ版もあります</a>).</p> - -<p>この例には、単純なカスタム要素 — <code><context-span></code> — があり、テキストを囲むことができます。</p> - -<pre class="brush: html notranslate"><h1>Host selectors <a href="#"><context-span>example</context-span></a></h1></pre> - -<p>要素のコンストラクターの中で、 <code>style</code> および <code>span</code> 要素を生成し、 <code>span</code> の中をカスタム要素の内容で埋め、 <code>style</code> 要素をいくつかの CSS 規則で埋めます。</p> - -<pre class="brush: js notranslate">let style = document.createElement('style'); -let span = document.createElement('span'); -span.textContent = this.textContent; - -const shadowRoot = this.attachShadow({mode: 'open'}); -shadowRoot.appendChild(style); -shadowRoot.appendChild(span); - -style.textContent = 'span:hover { text-decoration: underline; }' + - ':host-context(h1) { font-style: italic; }' + - ':host-context(h1):after { content: " - no links in headers!" }' + - ':host-context(article, aside) { color: gray; }' + - ':host(.footer) { color : red; }' + - ':host { background: rgba(0,0,0,0.1); padding: 2px 5px; }';</pre> - -<p><code>:host-context(h1) { font-style: italic; }</code> および <code>:host-context(h1):after { content: " - no links in headers!" }</code> の規則は <code><h1></code> の中にある <code><context-span></code> 要素 (このインスタンスのシャドウホスト) のインスタンスをスタイル付けします。これは設計上、 <code><h1></code> 内部にカスタム要素が現れるべきではないことを明確にするために使用しています。</p> - -<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', '#host-selector', ':host-context()') }}</td> - <td>{{ Spec2('CSS Scope') }}</td> - <td>初回定義</td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> - -<p>{{Compat("css.selectors.host-context")}}</p> - -<h2 id="See_also" name="See_also">関連情報</h2> - -<ul> - <li><a href="/ja/docs/Web/Web_Components">ウェブコンポーネント</a></li> - <li>{{cssxref(":host")}}</li> - <li>{{cssxref(":host()")}}</li> -</ul> |
