Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A utility CSS class for removing margins on first and last child elements. For more info, see https://philkurth.com.au/tips/a-utility-css-class-for-removing-margins-on-first-and-last-child-elements/
.m-0-first-last > :first-child {
margin-top: 0;
}
.m-0-first-last > :last-child {
margin-bottom: 0;
}
// Define a mixin so we can use this anywhere we need it
@mixin first_last_marginless() {
> :first-child {
margin-top: 0;
}
> :last-child {
margin-bottom: 0;
}
}
// Set up a utility class using the mixin
.m-0-first-last {
@include first_last_marginless;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.