Last active
January 29, 2022 19:30
-
-
Save jenhuls/d19babfdbe8bee6a9f93ce9d174b6d12 to your computer and use it in GitHub Desktop.
[Dynamic Widths, Padding & Margins Sass Mixin] Allows for multiple units of measure including rem, %, px, ch, vh & vw. #scss
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
// ============================================================================================= | |
// ██████ ██ ██ ███ ██ █████ ███ ███ ██ ██████ | |
// ██ ██ ██ ██ ████ ██ ██ ██ ████ ████ ██ ██ | |
// ██ ██ ████ ██ ██ ██ ███████ ██ ████ ██ ██ ██ | |
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ | |
// ██████ ██ ██ ████ ██ ██ ██ ██ ██ ██████ | |
// ██████ █████ ██████ ██████ ██ ███ ██ ██████ | |
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ | |
// ██████ ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ | |
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ | |
// ██ ██ ██ ██████ ██████ ██ ██ ████ ██████ ▄█ | |
// ███ ███ █████ ██████ ██████ ██ ███ ██ ███████ | |
// ████ ████ ██ ██ ██ ██ ██ ██ ████ ██ ██ | |
// ██ ████ ██ ███████ ██████ ██ ███ ██ ██ ██ ██ ███████ | |
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ | |
// ██ ██ ██ ██ ██ ██ ██████ ██ ██ ████ ███████ ▄█ | |
// ██ ██ ██ ██████ ████████ ██ ██ ███████ | |
// ██ ██ ██ ██ ██ ██ ██ ██ ██ | |
// ██ █ ██ ██ ██ ██ ██ ███████ ███████ | |
// ██ ███ ██ ██ ██ ██ ██ ██ ██ ██ | |
// ███ ███ ██ ██████ ██ ██ ██ ███████ | |
/// @usage | |
/// <div class="m-r-3vw m-t-10px m-b-5% p-3vw width-50%"></div> | |
/// @source | |
/// https://medium.com/@sajinsatheesan995/scss-dynamic-helper-class-functions-like-padding-margin-and-width-31b48337573 | |
// ============================================================================================= | |
$position: ( | |
top: 't', | |
right: 'r', | |
left: 'l', | |
bottom: 'b', | |
); | |
$unit: ( | |
rem: 'rem', | |
per: '%', | |
px: 'px', | |
vh: 'vh', | |
vw: 'vw', | |
ch: 'ch', | |
); | |
@for $size from 0 through 100 { | |
@each $unit, $ut in $unit { | |
@each $position, $pos in $position { | |
.m-#{$pos}-#{$size}#{$unit} { | |
margin-#{$position}: #{$size}#{$ut}; | |
} | |
.p-#{$pos}-#{$size}#{$unit} { | |
padding-#{$position}: #{$size}#{$ut}; | |
} | |
} | |
.m-#{$size}#{$unit} { | |
margin: #{$size}#{$ut}; | |
} | |
.p-#{$size}#{$unit} { | |
padding: #{$size}#{$ut}; | |
} | |
.w-#{$size}#{$unit} { | |
width: #{$size}#{$ut} !important; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment