Skip to content

Instantly share code, notes, and snippets.

@dtuite
Created December 23, 2015 13:41
Show Gist options
  • Save dtuite/3d1bbf70bf0027ad4298 to your computer and use it in GitHub Desktop.
Save dtuite/3d1bbf70bf0027ad4298 to your computer and use it in GitHub Desktop.
SCSS Loop for defining margin helpers.
$distances: ("s": 10px, "m": 25px);
$sides: left, top, bottom, right;
// This nested loop defines a set of spacer classes which we can use to place margins between
// elements.
//
// It generates slelectors which look like this:
//
// .ml--s {
// margin-left: 10px;
// }
// .mt--m {
// margin-left: 25px;
// }
//
// The naming scheme is [m]argin[l]eft--[s]mall, [m]argin[t]op--[m]edium etc.
@each $label, $distance in $distances {
@each $side in $sides {
.m#{str-slice($side, 0, 1)}--#{$label} {
margin-#{$side}: $distance;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment