csspoo

Search

Tags

  • Animation 1
  • Hover 2

Feed

RSS2.0
  • 2019-11-23

    Select all except last

    Author

    Jens Törnell

    Comments

    Start a discussion

    In common cases, you may need to put a margin-bottom to all elements except the last one.

    It's easy! Just use :not(:last-child).

    List example

    Full page

    li:not(:last-child) {
      margin-bottom: 1rem;
    }
    <ul>
      <li>List item 1</li>
      <li>List item 2</li>
      <li>List item 3</li>
    </ul>

    Sources:

    • https://stackoverflow.com/questions/2573544/how-can-i-select-all-children-of-an-element-except-the-last-child/2573566

    If you like this post, please share it! Tweet this!

  • Write for us
  • Contact us
  • About
  • License
Copyright © 2019

This page uses cookies for Google Analytics.