Created
April 19, 2022 07:59
-
-
Save squio/bfaad5fe00ab1952c841b50703587b19 to your computer and use it in GitHub Desktop.
Convert size in rem to pixel size based on computedStyle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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