Created
December 5, 2023 11:42
-
-
Save esedic/bf6451b8ddfdc654c23adea97095780c to your computer and use it in GitHub Desktop.
Calculate em to pixel value with JavaScript
This file contains 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
function em2px(em) { | |
return Number(em) * Number(window.getComputedStyle(document.body).getPropertyValue('font-size').match(/\d+/)[0]); | |
} | |
console.log(em2px(2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment