Skip to content

Instantly share code, notes, and snippets.

@markhalliwell
Created January 27, 2015 18:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save markhalliwell/e04d2775854fd24b56fb to your computer and use it in GitHub Desktop.
Save markhalliwell/e04d2775854fd24b56fb to your computer and use it in GitHub Desktop.
SASS Helper Classes
// Helper classes.
@each $property in (border, margin, padding) {
@each $direction in ('', -left, -right, -top, -bottom) {
.#{$property}#{$direction} {
@if $property == border {
#{$property}#{$direction}: 1px solid $gray-lighter;
}
@else {
#{$property}#{$direction}: 1em;
}
@if $direction == -top {
&:not(.no-first):first-of-type {
#{$property}#{$direction}: 0;
}
}
@else if $direction == -bottom {
&:not(.no-last):last-of-type {
#{$property}#{$direction}: 0;
}
}
}
.no-#{$property}#{$direction} {
#{$property}#{$direction}: 0;
&.important {
#{$property}#{$direction}: 0 !important;
}
}
}
}
@markhalliwell
Copy link
Author

This creates the following classes, all of which can add a prefix of no- which would instead set the property to 0.

Border

Class Property
border border: 1px solid $gray-lighter;
border-left border-left: 1px solid $gray-lighter;
border-right border-right: 1px solid $gray-lighter;
border-top border-top: 1px solid $gray-lighter;
border-bottom border-bottom: 1px solid $gray-lighter;

Margin

Class Property
margin margin: 1em;
margin-left margin-left: 1em;
margin-right margin-right: 1em;
margin-top margin-top: 1em;
margin-bottom margin-bottom: 1em;

Padding

Class Property
padding padding: 1em;
padding-left padding-left: 1em;
padding-right padding-right: 1em;
padding-top padding-top: 1em;
padding-bottom padding-bottom: 1em;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment