Skip to content

Instantly share code, notes, and snippets.

@poloey
Created December 4, 2017 17:10
Show Gist options
  • Save poloey/401d5f8763a9fa761369b05bfd8bce6b to your computer and use it in GitHub Desktop.
Save poloey/401d5f8763a9fa761369b05bfd8bce6b to your computer and use it in GitHub Desktop.
bootstrap spacing in sass using for and each loop
/*
only sides
*/
$sides: (top, bottom, left, right);
@for $i from 1 through 8 {
@each $side in $sides {
.m#{str_slice($side, 0, 1)}-#{$i} {
margin-#{$side}: #{$i / 2}em ;
}
.p#{str_slice($side, 0, 1)}-#{$i} {
padding-#{$side}: #{$i / 2}em ;
}
}
}
/*
with x, y and itself
*/
$sides: (top, bottom, left, right);
@for $i from 1 through 8 {
.m-#{$i} {
margin: #{$i / 2}em;
}
.p-#{$i} {
padding: #{$i / 2}em;
}
.mx-#{$i} {
margin: 0 #{$i / 2}em;
}
.px-#{$i} {
padding: 0 #{$i / 2}em;
}
.my-#{$i} {
margin: #{$i / 2}em 0;
}
.py-#{$i} {
padding: #{$i / 2}em 0;
}
@each $side in $sides {
.m#{str_slice($side, 0, 1)}-#{$i} {
margin-#{$side}: #{$i / 2}em ;
}
.p#{str_slice($side, 0, 1)}-#{$i} {
padding-#{$side}: #{$i / 2}em ;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment