Last active
December 1, 2016 04:04
-
-
Save joshuacerbito/efa04b972a6bfd5ee61f92caab72e112 to your computer and use it in GitHub Desktop.
Converts pixel values to rem
This file contains 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
//------------------------------------------------------------------*\ | |
// PIXEL TO REM | |
// converts px to rem | |
// note: uses @strip-units and $em-base | |
// usage: (https://jsfiddle.net/joshuacerbito/10q09tww/) | |
// width: rem(760); | |
// padding: rem(30 0 10); | |
//------------------------------------------------------------------*\ | |
$base-font-size: 16px; | |
@function strip-units($value) { | |
@return ($value / ($value * 0 + 1)); | |
} | |
@function rem($target) { | |
$max: length($target); | |
$values: (); | |
$context: if(variable-exists(base-font-size), $base-font-size, 16); | |
@for $i from 1 through $max { | |
$x: (nth($target, $i) / $context) * 1rem; | |
@if abs($x) == 0 { | |
$values: append($values, 0); | |
} | |
@else { | |
$values: append($values, $x); | |
} | |
} | |
@return $values; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment