以下のようなメニューを作るときに最後の要素以外にboarder
を入れて区切り線をいれたいときに:not
と:last-child
を使うと簡単にできたのでメモ📝
See the Pen menu-sample by madogiwa (@madogiwa0124) on CodePen.
やり方は簡単で以下のような:not(:last-child)
で疑似クラスを否定したセレクターを入れてあげれば🙆♂️
.menu-item:not(:last-child) { border-bottom: 1px solid grey; }
デフォルトボーダーありにしておいて:last-child
でunset
するよりも直感的で良い👍
.menu-item { border-bottom: 1px solid grey; } .menu-item:last-child { border-bottom: unset; }
考えてみれば当たり前ですが疑似クラスを入れ子に出来るの便利!