Skip to content

Instantly share code, notes, and snippets.

@weblancaster
Created September 22, 2013 18:18
Show Gist options
  • Save weblancaster/6662409 to your computer and use it in GitHub Desktop.
Save weblancaster/6662409 to your computer and use it in GitHub Desktop.
px to em
// It strips the unit of measure and returns it
@function strip-unit($num) {
@return $num / ($num * 0 + 1);
}
// Converts "px" to "em" using the ($)em-base
@function convert-to-em($value, $base-value: $em-base) {
$value: strip-unit($value) / strip-unit($base-value) * 1em;
@if ($value == 0em) { $value: 0; } // Turn 0em into 0
@return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment