CSS Variables in Firefox 31 – new syntax
jan.rs
jan.rs
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...).
The "var()" function is just.. redundant. Or maybe I'm missing something?
http://lists.w3.org/Archives/Public/www-style/2014Mar/0261.h...
And later on the justification for not using $ or @:
http://lists.w3.org/Archives/Public/www-style/2014Mar/0400.h...
There's also the issue that this needs to be backwards compatible with parsers that don't support the syntax, and apparently because the variables cascade that makes it harder still. I agree it's ugly though.
"> As far as I understand, the main reason of why Tab's original idea of using `$` has eventually been dropped was some uncertainty about its possible extensibility for being used in property _names_ besides property _values_.
The reason it got dropped is that some people (including Tab) do believe we should reserve $ for mixins and other preprocessor-like operations which may potentially be added to the language at some point. e.g. futuristic things like:
@define apply-2d-transform(initial-scale, initial-rotation, ...) {
...
my-transform-scaling: $initial-scale;
my-transform-rotation: $initial-rotation;
...
transform:
scale(get(my-transform-scaling))
rotate(get(my-transform-rotation))
translate(get(my-transform-translation));
will-change[]:
transform;
}
.some-element {
$apply-2d-transform(...);
transition[]: transform 0.5s ease-in-out;
}
.some-element:hover {
my-transform-scale: 1.1;
}
but this syntax was just made for this example, final milage may look
completely different and/or offer different features)" $myColor: #fff;
a {
color: $myColor;
}
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
.box { @include border-radius(10px); }The rationale for the "--" sigil matches what I'd expected, but I don't understand: why not just `name: --value` ?
I am convinced that at this point CSS is a clusterfuck that should be killed with fire.
Watch the video!
Once an easy-to-use syntax is published, toolchains that parse CSS will update as fast as they can! But "--"? Everybody will stick to the old standard and never want to upgrade.
LESS and SASS are much better about variables, what the heck were they thinking?
background-color: var(--best-gray-ever);
Not exactly intuitive or easy to parse at a glance.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
> what the heck were they thinking?
...At first place when they wrote CSS.
CSS is a disaster,and one of the worst spec ever written in my book.
> 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.
Aside from HTML,CSS and JS are "defacto" standards since vendors werent able to agree on a better spec when they should have. only developpers can fix these with tools they build.Devs cant rely on these technologies on their own.That's why they have CSS and JS preprocessors.Because while it's crap at the end of the day devs need to build on top of that crap.
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`.
font-color : red;
comprises a "property" (left) and a "value" (right). The draft W3C proposal allows you to specify a "custom property" and assign a value to it, thus: --header-bg-colour : #ff5533;
You can then reference this elsewhere by saying: header { background-color : var(--header-bg-colour); }
Isn't that just how you use a variable (written as $header-bg-colour) in Sass?[1] http://stackoverflow.com/questions/18466569/enable-experimen...
Do you remember the type attribute?
<style type="text/css">...</style>
That was originally put there so we could have different types of stylesheet languages, instead of everyone having to use CSS all of the time. Maybe browsers should incorporate the most popular LESS and SASS projects so that they can support type="text/less" and type="text/sass" too. Some workaround will be needed for old browsers (a javascript shim that retrieves server-compiled css) during the transition period, but eventually we'd end up with being able to use LESS, SASS, and CSS where needed, interchangably.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.
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.
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.
background-color: var(color);? background-color: currentColor;
Fully supported in all modern browsers. http://devdocs.io/css/color_value#currentColor_keywordPreprocessors are an inferior solution, limited by the semantics of CSS and leading, by the pervasive use of macros, to needlessly large CSS file sizes.
$("<div>")
.css({width: 100, height: 20, color: 'red'})
.appendTo(container);
Then, since these are just values in normal javascript code, you can refactor as normal. Pull commonly used patterns out into functions (e.g. `importantText(16, "size 16 important text goes here")`).Most styles in the applications I write tend to be inextricably linked to the layout and function of a component (e.g., tabs should be next to each other); in the rare case that a style needs to be customized in different locations or at different times, it becomes a parameter (e.g. `confirmDialog(textStyle, message, onOk, onCancel)`)
No extra tools are needed, beyond jQuery (building up the DOM without jQuery or something like it is awful).
Running JavaScript in your browser automatically from any site that you visit is pretty darn scary when you think about it. You can protect from a whole host of vulnerabilities by disabling it, and then whitelisting only hosts which you trust.