Skip to content

Instantly share code, notes, and snippets.

@fstorr
Created April 17, 2013 18:22
Show Gist options
  • Save fstorr/5406527 to your computer and use it in GitHub Desktop.
Save fstorr/5406527 to your computer and use it in GitHub Desktop.
SASS functions for px to em and em to px
$eminpx:14;
@function pxtoem($target, $context:$eminpx){
@return #{$target/$context}em;
}
@function emtopx($target, $context:$eminpx){
@return #{$target*$context}px;
}
/* this can take one or two arguments:
margin-bottom: pxtoem(10); // this will use the $eminpx variable as the second value
margin-bottom: pxtoem(10,18);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment