Skip to content

Instantly share code, notes, and snippets.

@poeticninja
Last active February 24, 2017 22:55
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 poeticninja/70717c214266af8237fc203ef22dc705 to your computer and use it in GitHub Desktop.
Save poeticninja/70717c214266af8237fc203ef22dc705 to your computer and use it in GitHub Desktop.
Spacing for styles
@mixin spacing($prop: padding, $dir: top, $value: 1) {
#{$prop}-#{$dir}: $value;
}
@function initial($string) {
@return str-slice($string, 0, 1);
}
$properties: (
margin,
padding
);
$sizes: (
0: 0px,
1: 3px,
2: 5px,
3: 7px,
4: 10px,
5: 15px,
6: 25px,
7: 50px
);
$positions: (
top,
right,
bottom,
left
);
$elements: (
h1,
h2,
h3,
h4,
h5,
h6,
p,
li,
i,
a,
small,
ul,
ol,
form,
input,
button,
null
);
@each $element in $elements {
@each $prop in $properties {
@each $position in $positions {
@each $size_name, $size_value in $sizes {
#{$element}.#{initial($prop)}#{initial($position)}-#{$size_name} {
@include spacing($prop, $position, $size_value);
}
}
}
}
}
@poeticninja
Copy link
Author

Generates spacing classes for margin and padding.

.pl-5 {
  padding-left: 15px;
}

.mt-0 {
  margin-top: 0px;
}

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