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/_colon_last-child/index.html | 129 ++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 files/ja/web/css/_colon_last-child/index.html (limited to 'files/ja/web/css/_colon_last-child') diff --git a/files/ja/web/css/_colon_last-child/index.html b/files/ja/web/css/_colon_last-child/index.html new file mode 100644 index 0000000000..7c49e1ef58 --- /dev/null +++ b/files/ja/web/css/_colon_last-child/index.html @@ -0,0 +1,129 @@ +--- +title: ':last-child' +slug: 'Web/CSS/:last-child' +tags: + - CSS + - Layout + - Pseudo-class + - Reference + - Selector + - Web +translation_of: 'Web/CSS/:last-child' +--- +
{{CSSRef}}
+ +

:last-childCSS擬似クラスで、兄弟要素のグループの中で最後の要素を表します。

+ +
/* 兄弟要素の中で最後の <p> を
+   すべてを選択 */
+p:last-child {
+  color: lime;
+}
+ +
+

注: 当初の定義では、親のある要素のみが選択されていました。 Selectors Level 4 の初期に、これは必要なくなりました。

+
+ +

構文

+ +
{{csssyntax}}
+ +

+ +

基本的な例

+ +

HTML

+ +
<div>
+  <p>This text isn't selected.</p>
+  <p>This text is selected!</p>
+</div>
+
+<div>
+  <p>This text isn't selected.</p>
+  <h2>This text isn't selected: it's not a `p`.</h2>
+</div>
+
+ +

CSS

+ +
p:last-child {
+  color: lime;
+  background-color: black;
+  padding: 5px;
+}
+
+ +

結果

+ +

{{EmbedLiveSample('Basic_example', 500, 200)}}

+ +

リストのスタイル付け

+ +

HTML

+ +
<ul>
+  <li>Item 1</li>
+  <li>Item 2</li>
+  <li>Item 3
+    <ul>
+      <li>Item 3.1</li>
+      <li>Item 3.2</li>
+      <li>Item 3.3</li>
+    </ul>
+  </li>
+</ul>
+ +

CSS

+ +
ul li {
+  color: blue;
+}
+
+ul li:last-child {
+  border: 1px solid red;
+  color: red;
+}
+ +

結果

+ +

{{EmbedLiveSample('Styling_a_list')}}

+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('CSS4 Selectors', '#the-last-child-pseudo', ':last-child')}}{{Spec2('CSS4 Selectors')}}選択する要素に親を必要としないようにした。
{{SpecName('CSS3 Selectors', '#last-child-pseudo', ':last-child')}}{{Spec2('CSS3 Selectors')}}初回定義
+ +

ブラウザーの互換性

+ + + +

{{Compat("css.selectors.last-child")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf