Created
August 17, 2017 01:40
-
-
Save angeliquejw/c14011ef63aaad8b85904b25de32b2b9 to your computer and use it in GitHub Desktop.
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
// REM + PX Fallback | |
// Developed by Hugo Giraudel (@HugoGiraudel) | |
// Inspired by Hans Christian Reini (@drublic) | |
// Refined by Moving Primates (@movingprimates) & James Kyle (@thejameskyle) | |
$root-font-size: 16; | |
@function parseInt($n) { | |
@return $n / ($n * 0 + 1); | |
} | |
@mixin rem($property, $values) { | |
$px: (); | |
$rem: (); | |
$root: $root-font-size; | |
@each $value in $values { | |
@if $value == 0 or $value == auto { | |
$px: append($px, $value); | |
$rem: append($rem, $value); | |
} | |
@else if type-of($value) == number { | |
$unit: unit($value); | |
$val: parseInt($value); | |
@if $unit == "px" { | |
$px: append($px, $value); | |
$rem: append($rem, ($val / $root + rem)); | |
} | |
@if $unit == "rem" { | |
$px: append($px, ($val * $root + px)); | |
$rem: append($rem, $value); | |
} | |
} | |
@else { | |
$px: append($px, $value); | |
$rem: append($rem, $value); | |
} | |
} | |
@if $px == $rem { | |
#{$property}: $px; | |
} | |
@else { | |
#{$property}: $px; | |
#{$property}: $rem; | |
} | |
} | |
@function rem($value) { | |
$root: $root-font-size; | |
$val: parseInt($value); | |
$return: (); | |
@if unit($value) == "px" { | |
$return: append($return, ($val / $root + rem)); | |
} | |
@else { | |
$return: append($return, ($val * $root + px)); | |
} | |
@return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment