Skip to content

Instantly share code, notes, and snippets.

@christoshrousis
Last active October 8, 2020 04:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christoshrousis/0fbaaea1f4171c5da20b8d5d2dd59e39 to your computer and use it in GitHub Desktop.
Save christoshrousis/0fbaaea1f4171c5da20b8d5d2dd59e39 to your computer and use it in GitHub Desktop.
CSS Pixels to Rem Conversion using Browser Context. SCSS & SASS
// The base fontsize you want to use.
$browser-context: 16
@function rem($pixels, $context: $browser-context)
@if unitless($pixels)
$pixels: $pixels * 1px
@if unitless($context)
$context: $context * 1px
@return $pixels / $context * 1rem
// The base fontsize you want to use.
$browser-context: 16;
@function rem($pixels, $context: $browser-context) {
@if unitless($pixels) {
$pixels: $pixels * 1px;
}
@if unitless($context) {
$context: $context * 1px;
}
@return $pixels / $context * 1rem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment