Skip to content

Instantly share code, notes, and snippets.

@HelloTiago
Created August 20, 2014 12:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HelloTiago/f47bc50cce9a0a4b07fb to your computer and use it in GitHub Desktop.
Save HelloTiago/f47bc50cce9a0a4b07fb to your computer and use it in GitHub Desktop.
Simple SCSS function to convert pixels to rems.
/**
*
* Convert pixels to rems
* eg. for a relational value of 12px write rem(12)
* $base is usually the font-size on your body element.
* And it can be defined outside the function, in a variables.scss file for example.
*
**/
@function rem($pxval) {
@if not unitless($pxval) {
$pxval: strip-units($pxval);
}
$base: 16px;
@if not unitless($base) {
$base: strip-units($base);
}
@return ($pxval / $base) * 1rem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment