DEV Community

Cover image for A simple way reset last margin in css
Vladimir Schneider
Vladimir Schneider

Posted on

A simple way reset last margin in css

Fir example I have a To-Do list ul > li for short.

Between each li I have a margin-bottom.

.todo-item {
  margin-bottom: 1rem;
}

.todo-item:last-child {
  margin-bottom: 0;
}
Enter fullscreen mode Exit fullscreen mode

But you can use this for it:

.todo-item:not(:last-child) {
  margin-bottom: 1rem;
}
Enter fullscreen mode Exit fullscreen mode

:not has great Browsers support

Alt Text

Use and happy!

Top comments (0)