Created
March 30, 2018 17:45
-
-
Save swashcap/cbcdb744232a372338d69cac3efdf238 to your computer and use it in GitHub Desktop.
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
// Measure letter spacing on | |
// https://material-components-web.appspot.com/typography.html | |
Array.from(document.querySelectorAll('.demo-typography--section > *')).forEach((node) => { | |
const span = document.createElement('span') | |
const { fontSize, letterSpacing } = getComputedStyle(node) | |
const parsedFontSize = parseFloat(fontSize, 10) / 16 | |
const parsedLetterSpacing = parseFloat(letterSpacing, 10) / 16 | |
span.innerHTML = `<span style="background:#efefef;border-radius:2px;display:inline-block;font:12px/15px monospace;letter-spacing:normal;margin:0 0 4px 8px;padding:4px 8px;"> | |
font-size: ${Number.isNaN(parsedFontSize) ? fontSize : `${Math.round(parsedFontSize * 1000) / 1000}rem`}<br /> | |
letter-spacing: ${Number.isNaN(parsedLetterSpacing) ? letterSpacing : `${Math.round(parsedLetterSpacing * 1000) / 1000}rem`}</span>` | |
node.appendChild(span) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment