Skip to content

Instantly share code, notes, and snippets.

@theCrius
Last active January 26, 2018 11:43
Show Gist options
  • Save theCrius/9617857e14205a9c55ba1cbe31d89be5 to your computer and use it in GitHub Desktop.
Save theCrius/9617857e14205a9c55ba1cbe31d89be5 to your computer and use it in GitHub Desktop.
Simple helper in sass to manage fine-tuning of that goddamn html
/* usage example */
/* <div class="mt-5"></div> --> Set div with margin-top: 5px */
/* <div class="m-5"></div> --> Set div with margin: 5px */
/* <div class="my-5"></div> --> Set div with margin-top: 5px, margin-bottom: 5px */
/* Spacing Helpers */
$spaces: (1, 2, 3, 4, 5, 10, 15, 20, 25, 30);
$sides: ('t', 'b', 'l', 'r', 'x', 'y', '');
@each $space in $spaces {
@each $side in $sides {
@if $side == '' {
.m#{$space} {
margin: #{$space}px;
}
.p#{$space} {
padding: #{$space}px;
}
} @elseif $side == 'x' {
.m#{$space} {
margin-right: #{$space}px;
margin-left: #{$space}px;
}
.p#{$space} {
padding-right: #{$space}px;
padding-left: #{$space}px;
}
} @elseif $side == 'y' {
.m#{$space} {
margin-top: #{$space}px;
margin-bottom: #{$space}px;
}
.p#{$space} {
padding-top: #{$space}px;
padding-bottom: #{$space}px;
}
} @else {
.m#{str-slice($side, 0, 1)}#{$space} {
margin-#{$side}: #{$space}px;
}
.p#{str-slice($side, 0, 1)}#{$space} {
padding-#{$side}: #{$space}px;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment