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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay