Skip to content

Conversation

@sideshowbarker
Copy link
Member

This change is a temporary workaround that adds an interim/initial/partial level
of support for handling CSS custom properties and the var(...) function. The
intent is that we’ll add full support later, and then at that time back this
change out — or else at least just use it as a starting point for full support.

This change simply allows declarations to contain custom property names (that
is, identifiers starting with two dashes) and to contain the var(...) function
(with a custom property name as the first argument). Beyond that, it doesn’t add
any checking to report an error if a var(...) function contains a custom
property name that the stylesheet hasn’t actually defined, and no checking to
report an error if a particular property has an expression with a var(...)
function which resolves to a value that’s not allowed for that property.

Addresses #111

@sideshowbarker sideshowbarker force-pushed the sideshowbarker/css-variables-interim-support branch from 93be7a2 to 796ed48 Compare February 15, 2018 10:59
@sideshowbarker sideshowbarker force-pushed the sideshowbarker/css-variables-interim-support branch from 796ed48 to a125bf0 Compare March 10, 2018 23:52
@sideshowbarker sideshowbarker force-pushed the sideshowbarker/css-variables-interim-support branch from 1ce26b3 to e6d27ee Compare June 7, 2018 01:26
This change is a temporary workaround that adds an interim/initial/partial level
of support for handling CSS custom properties and the `var(...)` function. The
intent is that we’ll add full support later, and then at that time back this
change out — or else at least just use it as a starting point for full support.

This change simply allows declarations to contain custom property names (that
is, identifiers starting with two dashes) and to contain the `var(...)` function
(with a custom property name as the first argument). Beyond that, it doesn’t add
any checking to report an error if a `var(...)` function contains a custom
property name that the stylesheet hasn’t actually defined, and no checking to
report an error if a particular property has an expression with a `var(...)`
function which resolves to a value that’s not allowed for that property.

Addresses #111
@sideshowbarker sideshowbarker force-pushed the sideshowbarker/css-variables-interim-support branch from e6d27ee to 46f3747 Compare August 17, 2020 17:44
@ylafon ylafon merged commit bb0777e into master Sep 17, 2020
@sideshowbarker sideshowbarker deleted the sideshowbarker/css-variables-interim-support branch May 21, 2021 11:00
@najamelan
Copy link

Could this be deployed? My school insists our code passes the validator which means I might have to rewrite my project without CSS variables because the validator is not up to date...

@saschanaz
Copy link
Member

It seems there are a few remaining issues e.g. #295 and #303. Probably better to keep tracking it there.

@najamelan
Copy link

najamelan commented Jul 12, 2021

@saschanaz Thanks, I hadn't seen those issues. They don't seem to mention any reason not to deploy an update to the live validator however. Since this was merged 10 months ago it looks like all that is missing is a roll out.

@saschanaz
Copy link
Member

@najamelan
Copy link

@sashanaz My apologies. I got confused. I get errors on code like this:

.search
{
   --search-height: 14.5rem;
   --search-radius: calc( var(--search-height) / 3 );
}

Since it throws warnings for the variables and the line here throws an error right after the var() I thought it was related. It looks like it's rather choking on the mathematical operator combined with a variable. It does not have trouble with calc( 5rem / 3 );. It does not like other arithmetic operators either.

AFAICT This is correct CSS code. Maybe that's an issue with this PR not supporting operators on variables?

@najamelan
Copy link

najamelan commented Jul 12, 2021

Looking through the diffs here it's quite hard to tell what's going on not knowing the grammar syntax used. Maybe @sideshowbarker can clarify whether this code was intended to pass or not...

@sideshowbarker
Copy link
Member Author

.search
{
   --search-height: 14.5rem;
   --search-radius: calc( var(--search-height) / 3 );
}

That’s valid per spec.

The fact that the validator doesn’t recognize it as valid is a bug in the validator.

There are many such cases of valid CSS using custom properties and certain functions that are known to fail in the validator. The cause is that the validator doesn’t actually yet have support for custom properties.

And the solution is that someone needs to update the validator code to add real support for custom properties. Nobody is currently working on that, though. So I don’t expect anything to change around this any time soon.

@najamelan
Copy link

@sideshowbarker Thanks for clarifying. Hopefully my evaluator will let me pass the exercise with css variables thanks to your comment. Btw just want to say, I 💖 MDN. Many thanks for your hard work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants