W3C home > Mailing lists > Public > www-style@w3.org > April 2012

Re: [css-variables] Should var properties respect !important?

From: Chris Eppstein <chris@eppsteins.net>
Date: Mon, 2 Apr 2012 20:04:16 -0700
Message-ID: <CANyEp6WfLu6c2Z69Qe9ncWp95KtcLMZ4=RT-Qnxo+gxrT3z1dA@mail.gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: www-style list <www-style@w3.org>
My experience with variables in stylesheets is that you never want to join
the "importantness" aspect with the "value" aspect. That is, the !important
modifier would be applied to the property when you reference the variable,
not as part of the variable value itself.

So if !important does anything I guess it would affect the variable
resolution, but I have to say that I really hate this idea and so I think
!important should be a syntax error in all cases of setting a variable's
value. If people end up having a problem we can add important in, but once
we add it we can't take it out.

Chris

On Mon, Apr 2, 2012 at 6:31 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:

> While implementing the parsing side of Variables recently, Luke
> realized that it's unclear whether an !important token at the end of a
> variable's value actually makes it important, or if it's just treated
> as part of the variable's value.  I'm not sure which option is the
> best, but here are some arguments for both.
>
> 1) Treat !important as part of the variable's value
>
> This option reduces the amount of interpretation on the var property's
> value, which is currently *almost* entirely uninterpreted (only var()
> references are expanded within it).
>
> Within (1), there are three sub-options:
>
> 1a) If variable expansion places an !important at the end of a
> property value, pay attention to it
>
> This makes sense because it's consistent with "expand variables then
> parse like normal", but I don't think it's workable.  Expansion
> doesn't occur until computed-value time, long after the cascade is
> run, and !important affects the cascade.  Thus, this appears to be a
> major violation of the value computation layering.
>
> 1b) If variable expansion produces an !important at the end of a
> property value, ignore it.  (!important appearing anywhere else is a
> syntax error, like usual)
>
> This is the minimal change - you expand variables, parse like normal,
> and then simply ignore a trailing !important because it's too late to
> act on.
>
> 1c) If variable expansion produces an !important token anywhere, ignore it.
>
> This is somewhat inconsistent with "expand variables then parse like
> normal", but it has the benefit of being stable across small edits -
> adding something to a property such that the "!important"-carrying var
> is no longer the last component won't cause a sudden mysterious syntax
> error.
>
> 2) Treat !important like normal, and have it effect the cascade (and
> not be part of the variable's value)
>
> The benefit of this is that you have the normal !important behavior,
> which may be less surprising.  Though using !important is *usually* a
> bad idea, on occasion it's worthwhile, and this preserves that ability
> for those cases.
>
> This also has sub-options:
>
> 2a) If a non-trailing !important appears in a var property, it's a syntax
> error.
>
> This prevents us from getting into the (2b) and (2c) situations
> entirely, but it means more preprocessing of variables.  Every
> restriction we place on a variable's value reduces its utility as a
> generic cascade-using information carrier, which I consider an
> important use-case (that is, using var properties to attach data to
> the DOM for JS purposes, rather than using them in the var()
> function).
>
> 2b) and 2c) Non-trailing !important in the var property isn't a syntax
> error; it's treated like (1b) or (1c) when expanded
>
>
> Like I said, I'm not strongly in favor of any option.  Thoughts?
>
> ~TJ
>
>
Received on Tuesday, 3 April 2012 03:04:47 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:52 GMT