Created
November 7, 2012 03:05
-
-
Save lean8086/4029359 to your computer and use it in GitHub Desktop.
Getting "1em" in pixels in 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
#em { | |
width: 1em; | |
visibility: hidden; | |
pointer-events: none; | |
position: absolute; | |
} |
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
<div id="em"></div> |
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
// Also works with offsetWidth and scrollWidth | |
var em = document.getElementById('em').clientWidth; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment