Live data from Hacker News

CSS Variables in Firefox 31 – new syntax

jan.rs

21–30 of 54 posts

Re: CSS Variables in Firefox 31 – new syntax

#21

Does the W3C not have internet access to learn about existing solutions and least try to emulate the good parts? 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.

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

Re: CSS Variables in Firefox 31 – new syntax

#24
post #15

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`.

I think this is just a problem of nomenclature. In CSS, a statement such as 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 (wr…

The similarity is only superficial. SASS variables are lexically scoped. CSS properties are cascading.

Re: CSS Variables in Firefox 31 – new syntax

#25

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.

As other posts have stated, CSS variables are not the same thing as preprocessor variables. Specifically, they cascade.

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.

Re: CSS Variables in Firefox 31 – new syntax

#26

Can anyone think of a use case for this beyond what a precompiler (Sass, Less, Stylus) can do?

I think the idea is you use this rather than a precompiler.

Changing bootstrap theme colors on the fly would be one reason to use this, even though you might be compiling bootstrap on each build.

Re: CSS Variables in Firefox 31 – new syntax

#27
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.

Re: CSS Variables in Firefox 31 – new syntax

#28
post #21

Does the W3C not have internet access to learn about existing solutions and least try to emulate the good parts? 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.

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

Most of the members of whatwg also like the DRM bits.

Re: CSS Variables in Firefox 31 – new syntax

#29
post #25

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.

As other posts have stated, CSS variables are not the same thing as preprocessor variables. Specifically, they cascade. 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.

Thanks for the break down. I'm not seeing the benefit of variables cascading, though.

Re: CSS Variables in Firefox 31 – new syntax

#30

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.

What's the best solution for writing styles exclusively in JS and avoiding CSS completely?
Post reply on HN