News for hackers. Stuff that matters.
Re:CSS Variables landing in Chrome 49 by hanniabu on Sunday February 07, 2016 @02:40PM (#11054411)
I'm not a fan of this...

/* JS */ var styles = getComputedStyle(document.documentElement); var value = String(styles.getPropertyValue('--primary-color')).trim(); // value = 'red'

Rather than calling '--primary-color', you should really be able to call 'color' which points to the variable and will still return red. Otherwise you'll have to know the name of each variable being used, which is much more difficult than knowing the property.

Re:CSS Variables landing in Chrome 49 by spankalee on Sunday February 07, 2016 @03:49PM (#11054756)
Variables are ultimately used somewhere to set a property, with something like

    color: var(--primary-color);
If care about that property, and not the variable, then get it as usual:

    let value = styles['color']; // 'red'
Re:CSS Variables landing in Chrome 49 by masklinn on Sunday February 07, 2016 @02:42PM (#11054427)
The point of variables is that you can reuse them, and more importantly changing the variable dynamically changes all of its uses.

So of course you have to know the name of the variables, they're an API for your CSS.

Re:CSS Variables landing in Chrome 49 by TabAtkins on Monday February 08, 2016 @01:23PM (#11059881)
That's exactly what you can do. var() is replaced at computed-value time, so calling gCS().color will return "red" or whatever.

If you use an API that gives you the value at an earlier time, like el.style.color (which is "specified value"), you'll see the var().

Re:CSS Variables landing in Chrome 49 by TazeTSchnitzel on Sunday February 07, 2016 @03:51PM (#11054763)
Well, you can also get the computed style for 'color'. What ever made you think you couldn't?