Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mishterk
Last active October 1, 2019 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mishterk/301657a3293f4337fb9415b567a3643f to your computer and use it in GitHub Desktop.
Save mishterk/301657a3293f4337fb9415b567a3643f to your computer and use it in GitHub Desktop.
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