Skip to content

Instantly share code, notes, and snippets.

@mactanxin
Created January 26, 2022 08:46
Show Gist options
  • Save mactanxin/e6b36151979daf114b3a2180f1cdb6cc to your computer and use it in GitHub Desktop.
Save mactanxin/e6b36151979daf114b3a2180f1cdb6cc to your computer and use it in GitHub Desktop.
$margin-unit: 4;
$padding-unit: 4;
$spacing-modifiers: (
'ma': margin,
'mx': margin,
'my': margin,
'mt': margin-top,
'mr': margin-right,
'mb': margin-bottom,
'ml': margin-left,
'pa': padding,
'px': padding,
'py': padding,
'pt': padding-top,
'pr': padding-right,
'pb': padding-bottom,
'pl': padding-left
);
@mixin create-spacing-classes($modifier, $value) {
@for $i from 1 through 10 {
@if ($modifier == 'mx' or $modifier == 'px') {
.#{$modifier}-#{$i} {
#{$value}: 0 unquote(($i * $margin-unit) + 'px');
}
} @else if ($modifier == 'my' or $modifier == 'py') {
.#{$modifier}-#{$i} {
#{$value}: unquote(($i * $margin-unit) + 'px') 0;
}
} @else {
.#{$modifier}-#{$i} {
#{$value}: unquote(($i * $margin-unit) + 'px');
}
}
}
}
@each $modifier, $value in $spacing-modifiers {
@include create-spacing-classes($modifier, $value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment