Skip to content

Instantly share code, notes, and snippets.

@squio
Created April 19, 2022 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squio/bfaad5fe00ab1952c841b50703587b19 to your computer and use it in GitHub Desktop.
Save squio/bfaad5fe00ab1952c841b50703587b19 to your computer and use it in GitHub Desktop.
Convert size in rem to pixel size based on computedStyle
export function convertRemToPixels(rem: number) {
if (document?.documentElement) {
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
} else {
console.warn('No "document" context, unable to calculate effective pixel size');
return rem;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment