Skip to content

Instantly share code, notes, and snippets.

@nhatkha1407
Last active October 7, 2020 10:23
Show Gist options
  • Save nhatkha1407/1e80629a0cd91a2b2ef951e6f7b021b3 to your computer and use it in GitHub Desktop.
Save nhatkha1407/1e80629a0cd91a2b2ef951e6f7b021b3 to your computer and use it in GitHub Desktop.
Spacing Utilities
@mixin generate($prefix, $property) {
// List of sizes to generate for each
$sizes: [0, 0.25, 0.5, 1, 1.5, 3];
// Spacing to multiply the sizes by
$spacing: 1rem;
// Loop through all of the sizes(we use @for rather than @each, as we want access to the index)
@for $i from 1 through length($sizes) {
// Get the size for the current index
$size: nth($sizes, $i);
// Create the rule
.#{$prefix}-#{$i - 1} {
#{$property}: $spacing * $size;
}
}
}
@include generate(ml, margin-left);
@include generate(mr, margin-right);
@include generate(mt, margin-top);
@include generate(mb, margin-bottom);
@include generate(pl, padding-left);
@include generate(pr, padding-right);
@include generate(pt, padding-top);
@include generate(pb, padding-bottom);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment