Skip to content

Instantly share code, notes, and snippets.

@ericmasiello
Created March 6, 2020 20:59
Show Gist options
  • Select an option

  • Save ericmasiello/4c1e13fdd0cdbcc8d3f10b2c4a354c96 to your computer and use it in GitHub Desktop.

Select an option

Save ericmasiello/4c1e13fdd0cdbcc8d3f10b2c4a354c96 to your computer and use it in GitHub Desktop.
$base-font-size: 16;
// strips away any unit from a value: e.g. "16px" => 16
@function strip-unit($number) {
@if type-of($number) == 'number' and not unitless($number) {
@return $number / ($number * 0 + 1);
}
@return $number;
}
@function px-to-rem($size, $base: $base-font-size) {
$pxUnitless: strip-unit($size);
@return #{$pxUnitless / $base}rem;
}
.some-selector {
font-size: px-to-rem(20);
padding: px-to-rem(14) px-to-rem(32);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment