The w3c has been failing at their job for some 15 years now. Enabling drm in html5 and giving the mpaa a seat on their board should have been the last straw. Ignore them, and start looking to WhatWg
These are not like SASS variables. I think calling this variables is causing unnecessary confusion.
This feature adds custom properties. CSS had custom vendor properties like `-webkit-foo`, and now you can have your own properties with vendor == "", so it's `--foo`.
So in this article, the author says this is not supported on chrome. But in this stack question [1], chrome is clearly using it. Is the only difference the author is discussing that now firefox uses/supports "--" instead of "var-"?
I like it. The syntax actually feels more css-like to me than what most preprocessors use. But never mind the syntax, the killer feature us the cascading - that's what sells me on this vs SASS/LESS/etc. (And, having it native is also nice - this way I can just dump something on Github Pages and skip the compilation step.)
For one, it means that you don't need to have a precompiler step in the development process. You can more easily edit the value inline in your browser's developer tools. You can more easily put together simple static sites.
Another is that you can use it in conjunction with calc(), which you can't do in a preprocessor. Take a look at some example use cases for calc, which can't be done in a preprocessor: http://css-tricks.com/a-couple-of-use-cases-for-calc/ Now instead of just using constant values in those, you can use variables. This can be even more powerful for responsive designs, because you can set the variable to different values based on a media query.
The CSS use a couple of custom properties that define the foreground and background colors. Then, some elements redefine those custom properties (through CSS or JS) and that in turn makes all their children inherit the new custom properties' values and change their styles. This makes the rules that use the custom properties very general, and avoids the need to write more specific rules for the alternative colors. I hope this makes sense :)
I don't think this is possible to do with CSS preprocessors.
Because precompilers are sort of a disruption of the point of CSS to begin with. I know, I know, a lot of people use them, but using style sheets that require compilation pretty much defeats the purpose of separation.
Woah. CSS variables look like compiler flags. There goes the W3C reinventing the wheel when Sass, Less and others have already laid out how to assign variables just fine for years.
Why do you have to use var(--name) when the parser already knows it's a variable from the -- prefix? Surely property: --name; is nicer than property: var(--name); ?
Writing your styles in javascript is a better option. You get variables, as well as functions and modules (e.g. with browserify), all with sane syntax and semantics (no "cascade").
Preprocessors are an inferior solution, limited by the semantics of CSS and leading, by the pervasive use of macros, to needlessly large CSS file sizes.
[+] [-] bshimmin|11 years ago|reply
I'm sure it'll be a real joy to use that for anyone who's been using Sass or Less (and who doesn't, these days...).
[+] [-] galvin|11 years ago|reply
The "var()" function is just.. redundant. Or maybe I'm missing something?
[+] [-] ibotty|11 years ago|reply
[+] [-] sergiotapia|11 years ago|reply
LESS and SASS are much better about variables, what the heck were they thinking?
Not exactly intuitive or easy to parse at a glance.[+] [-] paulrouget|11 years ago|reply
I don't know, maybe about how to design a spec that is compatible with past and future CSS parsers and features?
People think it's so simple to come up with a new feature for CSS/HTML/JS, when actually, they have no idea how difficult it is.
They're smarter than that: http://www.xanthir.com/blog/b4KT0
[+] [-] ep103|11 years ago|reply
[+] [-] pornel|11 years ago|reply
This feature adds custom properties. CSS had custom vendor properties like `-webkit-foo`, and now you can have your own properties with vendor == "", so it's `--foo`.
[+] [-] bshimmin|11 years ago|reply
[+] [-] peaton|11 years ago|reply
[1] http://stackoverflow.com/questions/18466569/enable-experimen...
[+] [-] artursapek|11 years ago|reply
[+] [-] peterjmag|11 years ago|reply
[+] [-] nfriedly|11 years ago|reply
[+] [-] talmand|11 years ago|reply
[+] [-] arxpoetica|11 years ago|reply
[+] [-] lambda|11 years ago|reply
Another is that you can use it in conjunction with calc(), which you can't do in a preprocessor. Take a look at some example use cases for calc, which can't be done in a preprocessor: http://css-tricks.com/a-couple-of-use-cases-for-calc/ Now instead of just using constant values in those, you can use variables. This can be even more powerful for responsive designs, because you can set the variable to different values based on a media query.
[+] [-] epidemian|11 years ago|reply
The CSS use a couple of custom properties that define the foreground and background colors. Then, some elements redefine those custom properties (through CSS or JS) and that in turn makes all their children inherit the new custom properties' values and change their styles. This makes the rules that use the custom properties very general, and avoids the need to write more specific rules for the alternative colors. I hope this makes sense :)
I don't think this is possible to do with CSS preprocessors.
[+] [-] bshimmin|11 years ago|reply
[+] [-] silverbax88|11 years ago|reply
[+] [-] rubiquity|11 years ago|reply
[+] [-] gavinpc|11 years ago|reply
A preprocessor cannot possibly implement CSS variables with cascading because it the value is resolved against a live context.
In other words, you can actually change the variable at runtime with rules that target different selectors.
As such, the "variables" are in fact functions.
[+] [-] AshleysBrain|11 years ago|reply
[+] [-] ihuman|11 years ago|reply
[+] [-] bouncingsoul|11 years ago|reply
[+] [-] ahoge|11 years ago|reply
http://jsfiddle.net/QEJw9/
[+] [-] jasonpriestley|11 years ago|reply
Preprocessors are an inferior solution, limited by the semantics of CSS and leading, by the pervasive use of macros, to needlessly large CSS file sizes.
[+] [-] VMG|11 years ago|reply
[+] [-] kuschku|11 years ago|reply
[+] [-] chenglou|11 years ago|reply
[+] [-] est|11 years ago|reply
[+] [-] joesb|11 years ago|reply
[+] [-] Thiz|11 years ago|reply