Skip to content

Instantly share code, notes, and snippets.

@pgarciacamou
Created June 10, 2015 21:21
Show Gist options
  • Save pgarciacamou/3d46bcc19621f46f03d5 to your computer and use it in GitHub Desktop.
Save pgarciacamou/3d46bcc19621f46f03d5 to your computer and use it in GitHub Desktop.
Convert pixels to rems with JavaScript
var toRem = (function(){
var fontSize = parseFloat(window.getComputedStyle(document.querySelector("html"), null).getPropertyValue('font-size'));
return function toRem(px){
return px/fontSize;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment