Skip to content

Instantly share code, notes, and snippets.

@miladd3
Created June 8, 2022 12:35
Show Gist options
  • Save miladd3/e7b922893a6fb628093149b89b796da1 to your computer and use it in GitHub Desktop.
Save miladd3/e7b922893a6fb628093149b89b796da1 to your computer and use it in GitHub Desktop.
@function strip-unit($num) {
@return $num / ($num * 0 + 1);
}
@function convert-to-rem($value, $base-value: $rem-base) {
$value: strip-unit($value) / strip-unit($base-value) * 1rem;
@if ($value == 0rem) { $value: 0; } // Turn 0rem into 0
@return $value;
}
@function rem-calc($values, $base-value: $rem-base) {
$max: length($values);
@if $max == 1 { @return convert-to-rem(nth($values, 1), $base-value); }
$remValues: ();
@for $i from 1 through $max {
$remValues: append($remValues, convert-to-rem(nth($values, $i), $base-value));
}
@return $remValues;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment