「CSS」last-childでグループの中で最後の要素を取得する方法

2020年10月13日

構文
:last-child 疑似クラスは、兄弟要素のグループの中で最後の要素を表します。
htmlコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<div align="center">
<p>このテキストは選択されていません.</p>
<p>このテキストは選択されています</p>
</div>
<div class="cft">
<p>このテキストは選択されていません.</p>
<h2>このテキストは選択されていません、pタグでhない</h2>
</div>
<div align="center"> <p>このテキストは選択されていません.</p> <p>このテキストは選択されています</p> </div> <div class="cft"> <p>このテキストは選択されていません.</p> <h2>このテキストは選択されていません、pタグでhない</h2> </div>
<div align="center">
  <p>このテキストは選択されていません.</p>
  <p>このテキストは選択されています</p>
</div>

<div class="cft">
  <p>このテキストは選択されていません.</p>
  <h2>このテキストは選択されていません、pタグでhない</h2>
</div>

CSSコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
p:last-child {
background-color: green;
padding: 5px;
}
p:last-child { background-color: green; padding: 5px; }
p:last-child {
  background-color: green;
  padding: 5px;
}

 

CSS

Posted by arkgame