Re: [variables] invalid variables

On Thu, Nov 3, 2011 at 11:58 AM, Roland Steiner
<rolandsteiner@google.com> wrote:
> Hi all,
> Reading though the new variables spec
> (http://dev.w3.org/csswg/css-variables/), section 3.1, and examples 7 and 8
> specify that a property that is invalid at computed value time must evaluate
> to the property's initial value. IMHO this should rather be specified that
> the property is ignored (in line with invalid values
> in http://www.w3.org/TR/css3-values/) or perhaps evaluate to its default
> value, instead. (Inasmuch I think that using 'background-color' in those
> example is a bit unfortunate, as it'd evaluate to 'transparent'.)
> Apart from giving surprising results (IMHO), evaluating to the initial value
> would also prevent use cases like the following:
> .foo {
>   color: red; // default value
>   color: data(override-color); // override only if declared
> }
> .bar {
>   background-color: black;
>   background-color: data(bg-color);
>   background-color: linear-gradient(from top left to bottom right,
> data(from-color) 0%, data(to-color) 100%);
> }

"Ignoring" the declaration isn't really doable - it requires
remembering an arbitrary amount of declarations for a given property
on an element so you can reset back to a non-variable version.  All
engines currently optimize by throwing away the results of the cascade
once they find the declaration that wins, and I understand this is
fairly important for performance.

Resetting to the "default", which I assume means either the initial or
inherited value, rather than always using the initial value might be
okay.  Always choosing 'initial' is simpler, though, and considering
this is a failure mode that authors *shouldn't* be running into, I
don't know if we need to care about it.

Your use-case, though, seems to just be asking for the ability to
provide a default value for a variable if it happens to be
invalid/undefined.  I think this is a useful thing to want.  We can do
this by providing a default value as a second argument, analogous to
the attr() function.

~TJ

Received on Thursday, 3 November 2011 19:23:39 UTC