Skip to content

Instantly share code, notes, and snippets.

@codepunkt
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codepunkt/0bb4333566c2c1723150 to your computer and use it in GitHub Desktop.
Save codepunkt/0bb4333566c2c1723150 to your computer and use it in GitHub Desktop.
px to rem mixin
@function px-to-rem($val, $base: 16) {
// if it's a unitless number
@if type-of($val) == number and unitless($val) {
// don't convert 0
@if $val == 0 {
@return 0;
}
// assume its px and convert it to rem based on $base document font-size
@return #{$val / $base}rem;
}
@return $val;
}
@mixin rem($property, $values...) {
$max: length($values);
$value: '';
@for $i from 1 through $max {
$value: #{$value + px-to-rem(nth($values, $i))};
@if $i < $max {
$value: #{$value + " "};
}
}
#{$property}: $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment