Last active
April 26, 2020 15:45
-
-
Save krasenslavov/58c9510e4ccc00013faaa928bd9b8dcf to your computer and use it in GitHub Desktop.
Sass mixin to customize margin and padding. Visit blog posts https://bit.ly/3bg4Rqs
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
// _margin.scss | |
@mixin margin($uid: margin, $unit: px, $step: 10, $from: 0, $through: 3) { | |
$base: ( | |
'': '', | |
't': '-top', | |
'r': '-right', | |
'b': '-bottom', | |
'l': '-left', | |
'x': ('-left', '-right'), | |
'y': ('-top', '-bottom') | |
); | |
@for $i from $from through $through { | |
@each $prop, $value in $base { | |
@if length($value) > 1 { | |
.#{$uid}#{$prop}-#{$i} { | |
margin#{nth($value, 1)}: $i * $step#{$unit}; | |
margin#{nth($value, 2)}: $i * $step#{$unit}; | |
} | |
} @else { | |
.#{$uid}#{$prop}-#{$i} { | |
margin#{$value}: $i * $step#{$unit}; | |
} | |
} | |
} | |
} | |
} |
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
// _padding.scss | |
@mixin padding($uid: padding, $unit: px, $step: 10, $from: 0, $through: 3) { | |
$base: ( | |
'': '', | |
't': '-top', | |
'r': '-right', | |
'b': '-bottom', | |
'l': '-left', | |
'x': ('-left', '-right'), | |
'y': ('-top', '-bottom') | |
); | |
@for $i from $from through $through { | |
@each $prop, $value in $base { | |
@if length($value) > 1 { | |
.#{$uid}#{$prop}-#{$i} { | |
padding#{nth($value, 1)}: $i * $step#{$unit}; | |
padding#{nth($value, 2)}: $i * $step#{$unit}; | |
} | |
} @else { | |
.#{$uid}#{$prop}-#{$i} { | |
padding#{$value}: $i * $step#{$unit}; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment