Created
December 4, 2017 17:10
-
-
Save poloey/401d5f8763a9fa761369b05bfd8bce6b to your computer and use it in GitHub Desktop.
bootstrap spacing in sass using for and each loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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