Skip to content

Instantly share code, notes, and snippets.

@sean-codes
Created June 1, 2019 19:18
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 sean-codes/85557a30fd06b33f01385b150debf383 to your computer and use it in GitHub Desktop.
Save sean-codes/85557a30fd06b33f01385b150debf383 to your computer and use it in GitHub Desktop.
SCSS: utility classes for margin/padding
// whitespace
$whitespace: 1rem;
$whitespace-types: (
( 'short': p, 'long': padding ),
( 'short': m, 'long': margin )
);
$whitespace-directions: (
( 'name': t, 'prop': top ),
( 'name': b, 'prop': bottom ),
( 'name': l, 'prop': left ),
( 'name': r, 'prop': right )
);
@for $typeId from 1 through length($whitespace-types) {
$type: nth($whitespace-types, $typeId);
$short: map-get($type, 'short');
$long: map-get($type, 'long');
.#{$short}-half { #{$long}: $whitespace/2; }
@for $o from 1 through 5 {
.#{$short}-#{$o} { #{$long}: $whitespace * $o; }
}
@for $i from 1 through length($whitespace-directions) {
$direction: nth($whitespace-directions, $i);
$name: map-get($direction, 'name');
$prop: map-get($direction, 'prop');
$classPrefix: #{$short}#{$name};
$propPrefix: #{$long}-#{$prop};
.#{$classPrefix}-half { #{$propPrefix}: $whitespace/2; }
@for $o from 1 through 5 {
.#{$classPrefix}-#{$o} { #{$propPrefix}: $whitespace * $o; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment