Created
June 14, 2018 20:12
-
-
Save amiut/3e3e88a4937692cc9822eb66a44c08e2 to your computer and use it in GitHub Desktop.
Convert px values to rem in SASS
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
$html-base-font-size = 12px; | |
@function rem( $px ){ | |
@if( unit( $px ) == 'rem' ){ | |
@return $px; | |
} | |
@else if( unit($px) == 'px' ) { | |
@return ( $px / $html-base-font-size ) + 0rem; | |
} | |
@else if( unit( $px ) == '' ) { | |
@return ( ( $px + 0px ) / $html-base-font-size ) + 0rem; | |
} | |
@else { | |
@return $px; | |
} | |
} | |
.example{ | |
font-size: rem(14px); | |
font-size: rem(16); // unitless values are considered to be px | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment