Skip to content

Instantly share code, notes, and snippets.

@davidhellmann
Created October 18, 2020 17:55
Show Gist options
  • Save davidhellmann/e008322354f6b77ff83dfab7af025ff8 to your computer and use it in GitHub Desktop.
Save davidhellmann/e008322354f6b77ff83dfab7af025ff8 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
@mixin space($properties: padding, $factor: 1, $important: null) {
$multi: 1;
@if type-of($factor) == number {
@if $factor < 0 {
$factor: $factor * -1;
$multi: -1;
}
// Set Vars
$minValue: (1rem / 2) * $factor;
$maxValue: (2rem / 2) * $factor;
$min: 20rem;
$max: 100rem;
$slope: ($maxValue - $minValue) / ($max - $min);
$yAxisIntersection: -$min * $slope + $minValue;
@if $important == '!' {
$important: !important;
} @else {
$important: null;
}
@if type-of($properties) == list or type-of($properties) == string {
@each $property in $properties {
#{$property}: calc(clamp(#{$minValue}, calc(#{$yAxisIntersection + $slope * 100}vw), #{$maxValue}) * #{$multi});
}
} @else {
@error "$properties is not passed in correct. Must be a list!";
}
} @else {
@error "$factor is not passed in correct. Must be a number!";
}
}
div {
@include space(padding, 1);
@include space(margin, -2);
@include space(bottom, -2, '!');
}
// 16 * 1,2 * 1,2
div {
padding: calc(clamp(0.5rem, calc(1remvw), 1rem) * 1);
margin: calc(clamp(1rem, calc(2remvw), 2rem) * -1);
bottom: calc(clamp(1rem, calc(2remvw), 2rem) * -1);
}
{
"sass": {
"compiler": "Ruby Sass/3.7.4",
"extensions": {},
"syntax": "SCSS",
"outputStyle": "expanded"
},
"autoprefixer": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment