最初と最後の要素、CSS疑似クラス:first-childと:last-child
2017.09.07 2019.11.30
:first-child
疑似クラス :first-child
は子要素の一番最初に適応されます。
ol li:first-child { color: red; font-weight: bold; }
- リスト1
- リスト2
- リスト3
- リスト4
- リスト5
:last-child
疑似クラス :last-child
は子要素の一番最後に適応されます。
ol li:last-child { color: red; font-weight: bold; }
- リスト1
- リスト2
- リスト3
- リスト4
- リスト5
:nth-last-child(n)
疑似クラス :nth-last-child(n)
は子要素の最後からn番目に適応されます。
最後から2番目の場合
ol li:nth-last-child(2) { color: red; font-weight: bold; }
- リスト1
- リスト2
- リスト3
- リスト4
- リスト5