Last active
December 11, 2015 00:39
-
-
Save ocean90/4517823 to your computer and use it in GitHub Desktop.
SASS Mixin for converting px values to rem
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
| // Based on https://github.com/bitmanic/rem/ | |
| // Examples of usage: | |
| // text-shadow: rem( 1px 1px 0 #fff ); | |
| // font-size: rem( 16px ); | |
| // @include box-shadow( rem( -2px 2px 0 ) rgba(0,0,0,0.1) ); | |
| $baseline-px: 16px; | |
| @function rem( $px-values ) { | |
| $baseline-rem: $baseline-px / 1rem; | |
| @if type-of($px-values) == "number" { | |
| @return $px-values / $baseline-rem; | |
| } @else { | |
| // Create an empty list that we can dump values into | |
| $rem-values: unquote(""); | |
| @each $value in $px-values { | |
| @if type-of($value) != "number" { | |
| // If the value is no number, return the value as is | |
| $rem-values: append($rem-values, $value); | |
| } @else if $value == 0 { | |
| // If the value is zero, return 0 | |
| $rem-values: append($rem-values, 0); | |
| } @else { | |
| $rem-values: append($rem-values, $value / $baseline-rem); | |
| } | |
| } | |
| // Return the property and its list of converted values | |
| @return $rem-values; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment