Created
November 1, 2018 17:07
-
-
Save dinocarl/3d609ce2e68aa1117dadd11e23d54ce2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@function apply-unit($unit, $val) { | |
@return unquote('#{$val}#{$unit}'); | |
} | |
@function strip-unit($number) { | |
@if type-of($number) == 'number' and not unitless($number) { | |
@return $number / ($number * 0 + 1); | |
} | |
@return $number; | |
} | |
// shortcut function to apply px unit | |
@function px($val) { | |
@return apply-unit('px', $val); | |
} | |
// shortcut function to apply rem unit | |
@function rem($val) { | |
@return apply-unit('rem', $val); | |
} | |
// convert pixels to rems | |
@function px-to-rem($root, $size) { | |
@return rem( strip-unit( $size / $root ) ); | |
} | |
// mixin to output px-to-rem function | |
// inside a font-size attribute | |
@mixin rems($root, $size) { | |
// fallback to pixels | |
// turned off due to widespread | |
// browser support for rems | |
// font-size: px( strip-unit( $size ) ); | |
font-size: px-to-rem( $root, $size ); | |
} | |
$base-font-size: 16px; | |
// partially applied rems mixin with $base-font-size | |
@mixin grCom-rems($size) { | |
@include rems($base-font-size, $size); | |
} | |
.test { | |
@include grCom-rems(11); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment