diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/css/_colon_only-child | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/ja/web/css/_colon_only-child')
| -rw-r--r-- | files/ja/web/css/_colon_only-child/index.html | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/files/ja/web/css/_colon_only-child/index.html b/files/ja/web/css/_colon_only-child/index.html new file mode 100644 index 0000000000..89ce4eb5fd --- /dev/null +++ b/files/ja/web/css/_colon_only-child/index.html @@ -0,0 +1,141 @@ +--- +title: ':only-child' +slug: 'Web/CSS/:only-child' +tags: + - CSS + - ウェブ + - セレクター + - リファレンス + - レイアウト + - 擬似クラス +translation_of: 'Web/CSS/:only-child' +--- +<div>{{CSSRef}}</div> + +<p><a href="/ja/docs/Web/CSS">CSS</a> の <strong><code>:only-child</code></strong> <a href="/ja/docs/Web/CSS/Pseudo-classes" title="Pseudo-classes">疑似クラス</a>は、兄弟要素がない要素を表します。 <code>:first-child:last-child</code> または <code>:nth-child(1):nth-last-child(1)</code> と同じですが、詳細度はより低くなります。</p> + +<pre class="brush: css no-line-numbers">/* 親の唯一の子である <p> 要素をすべて選択 */ +p:only-child { + background-color: lime; +}</pre> + +<div class="note"> +<p><strong>メモ:</strong> 最初の定義では、親のある要素のみが選択されていました。 Selectors Level 4 の初期に、これは必要なくなりました。</p> +</div> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox">{{csssyntax}} +</pre> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Basic_example" name="Basic_example">基本的な例</h3> + +<h4 id="HTML">HTML</h4> + +<pre class="brush: html"><div> + <div>I am an only child.</div> +</div> + +<div> + <div>I am the 1st sibling.</div> + <div>I am the 2nd sibling.</div> + <div>I am the 3rd sibling, <div>but this is an only child.</div></div> +</div> +</pre> + +<h4 id="CSS">CSS</h4> + +<pre class="brush: css">div:only-child { + color: red; +} + +div { + display: inline-block; + margin: 6px; + outline: 1px solid; +} +</pre> + +<h4 id="Result" name="Result">結果</h4> + +<p>{{EmbedLiveSample('Basic_example','100%',180)}}</p> + +<h3 id="A_list_example" name="A_list_example">リストの例</h3> + +<h4 id="HTML_2">HTML</h4> + +<pre class="brush: html"><ol> + <li>First + <ul> + <li>This list has just one element.</li> + </ul> + </li> + <li>Second + <ul> + <li>This list has three elements.</li> + <li>This list has three elements.</li> + <li>This list has three elements.</li> + </ul> + </li> +</ol> +</pre> + +<h4 id="CSS_2">CSS</h4> + +<pre class="brush: css">li li { + list-style-type: disc; +} + +li:only-child { + color: red; + list-style-type: square; +}</pre> + +<h4 id="Result_2" name="Result_2">結果</h4> + +<p>{{EmbedLiveSample('A_list_example', '100%', 210)}}</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('CSS4 Selectors', '#only-child-pseudo', ':only-child')}}</td> + <td>{{Spec2('CSS4 Selectors')}}</td> + <td>選択する要素に親を必要としないようにした。</td> + </tr> + <tr> + <td>{{SpecName('CSS3 Selectors', '#only-child-pseudo', ':only-child')}}</td> + <td>{{Spec2('CSS3 Selectors')}}</td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div> +<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.only-child")}}</p> +</div> +</div> + +<h2 id="See_also" name="See_also">関連項目</h2> + +<ul> + <li>{{Cssxref(":only-of-type")}}</li> + <li>{{Cssxref(":first-child")}}</li> + <li>{{Cssxref(":last-child")}}</li> + <li>{{Cssxref(":nth-child")}}</li> +</ul> |
