Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manage margins so that the last element(s) have no margin(s)

Tags:

css

margin

I work with boxes and I want to always give the last element a "margin-bottom: 0". So first I give every element a "margin-bottom: 1em;". I now want to delete this margin bottom from the last element in my boxes but if there is an element within it doesn't work and I still have a margin at the bottom. any idea how to do this? It could be a paragraph or a DIV or SPAN or whatever, so I do not always want to do this by hand. I want to make a mixin wth this.

I tried:

section *+:last-child {
   margin-bottom: 0;
   border: 3px solid blue;
}

But in the last div there is a paragraph with margin so it doesn't work.

like image 996
Henning Fischer Avatar asked Mar 30 '16 23:03

Henning Fischer


1 Answers

You want to use :not(). That is,

section:not(:last-child) { margin-bottom:1em; }

My syntax might be wrong for what you're doing but that's a start.

like image 130
Rob Avatar answered Oct 04 '22 06:10

Rob