Last active
October 23, 2018 15:39
-
-
Save lomboboo/20916cc192e97f770e281a06180d37e7 to your computer and use it in GitHub Desktop.
SCSS margin/padding mixin with responsiveness
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
.mt-1 { | |
margin-top: 1rem; } | |
.pt-1 { | |
padding-top: 1rem; } | |
@media (min-width: 768px) { | |
.mt-sm-4 { | |
margin-top: 4rem; } | |
.pt-sm-4 { | |
padding-top: 4rem; } } | |
// ... etc |
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
$sides: ( | |
"": "", | |
"t": "top", | |
"b": "bottom", | |
"l": "left", | |
"r": "right", | |
); | |
$breakpoints: ( | |
"": "", | |
"xs": 576px, | |
"sm": 768px, | |
"md": 992px, | |
"lg": 1200px, | |
); | |
@each $breakName, $breakValue in $breakpoints { | |
@each $sideName, $sideValue in $sides { | |
@for $i from 0 through 10 { | |
$property: if($sideName == '', '', -#{$sideValue}); | |
$space: $i; | |
$selector: ''; | |
@if $breakName != "" { | |
$selector: #{$sideName}-#{$breakName}-#{$i}; | |
} @else { | |
$selector: #{$sideName}-#{$i}; | |
} | |
@if $breakName != "" { | |
@media (min-width: $breakValue) { | |
.m#{$selector} { | |
margin#{$property}: #{$space}rem; | |
} | |
.p#{$selector} { | |
padding#{$property}: #{$space}rem; | |
} | |
} | |
} @else { | |
.m#{$selector} { | |
margin#{$property}: #{$space}rem; | |
} | |
.p#{$selector} { | |
padding#{$property}: #{$space}rem; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment