:root {
var-header-color: #06c;
}
h1 { background-color: var(header-color); }
looks slightly hacky, but better than nothing at all I suppose... :root {
var-header-color: #06c;
}
h1 { background-color: var(header-color); }
looks slightly hacky, but better than nothing at all I suppose...But seriously, this is extremely consistant with other css directives. Yes, I'm still going to just use less / stylus / whatever, but browser based vars mean some interesting possibilities sans js.
This proposal by the W3C is definitely not-even-half-baked.
:root { $header-color: #06c; } h1 { background-color: $header-color; }
(Note that the spec's use of the :root pseudo is just to generically declare "global" variables that should apply to the whole page. If you're just using HTML, feel free to use "html" or "body" as the selector instead.)
I'm guessing the justification for the existence of the awkward var(varname) version is so that you can also have the parent-var(varname) notation.
I do think it's interesting how variables are scoped to dom nodes. Is there any reason it cannot be optional though, so if you omit it, it defaults to global?
$header-color: #06c; h1 { background-color: $header-color; }
I'm guessing the argument against, is that this requires too much of a change to CSS parsers, as it doesn't follow the standard form of <selector> { <properties> }. If that's really the reason it seems a bit of a shame though :/
:root{ def-primarycolor: blue; }
.x{ background-color: $primarycolor; }
edit: I think I'll stick to PHP variables in my CSS for now:
<?=$color1?>I understand the danger of introducing PHP to CSS though. I won't be making database calls or anything like that from a .css file.