Last active
May 30, 2019 12:04
-
-
Save jportella93/753886885bf6f14ff3959ed5530ab283 to your computer and use it in GitHub Desktop.
Set CSS variables and access them with JavaScript.
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
const stringVariable = getComputedStyle(document.documentElement) | |
.getPropertyValue('--height'); // '60px' | |
const heightInPx = Number(stringVariable.match(/[0-9]*/)[0]); // 60 |
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
:root { | |
--height: 60px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment