Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-var] var(property) #5729

Closed
Crissov opened this issue Nov 15, 2020 · 5 comments
Closed

[css-var] var(property) #5729

Crissov opened this issue Nov 15, 2020 · 5 comments
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-variables-1 Current Work

Comments

@Crissov
Copy link
Contributor

Crissov commented Nov 15, 2020

Will var(foo) always resolve to the value of the foo property if anything at all?
That is, currently foo is limited to a <dashed-ident> for custom properties, so always has a prefix of a double hyphen-minus --, but if var() was ever specified to accept other values then those would be the normal properties defined by CSS modules and never anything else.

bar 
{
  --color: orange;
  color: green;
  background-color: var(color, red); /* similar to `currentcolor` */
}
@castastrophe
Copy link

Very interesting idea. 🤔 Can you provide any more use-cases to help me grok the usefulness? Since you shared alternative ways to accomplish the same without var, I'm wondering if perhaps this is an ease-of-use concept or if there's ways to use this that fill functionality gaps.

@Crissov
Copy link
Contributor Author

Crissov commented Nov 20, 2020

I'm not really proposing to add this, but was just asking for clarification if this would be the only feasible meaning such var() references could ever have.

@TheComputerM
Copy link

The main benefit would be with numerical values:

.class {
  width: 10px;
  height: calc(var(width) + 5em);
}

@andruud
Copy link
Member

andruud commented Nov 26, 2020

(I think this adds too much complexity to be worth doing, but I'll play anyway):

Is there a benefit vs. just using custom props? E.g.

.class {
  --width: 10px;
  width: var(--width);
  height: calc(var(--width) + 5em);
}

@tabatkins
Copy link
Member

That would indeed be the only feasible meaning, yes.

This is explicitly off the table, however, because var-substitution has to know the full graph of variable dependencies to detect cycles. Normal properties can gain dependencies on each other in sometimes-nonobvious ways, making it hard to specify and potentially confusing to use; we also add new dependencies over time, which would break code currently relying on there not being such a dependency between two given properties. Custom properties, since they have no meaning whatsoever, don't suffer from either of these problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed as Question Answered Used when the issue is more of a question than a problem, and it's been answered. css-variables-1 Current Work
Projects
None yet
Development

No branches or pull requests

5 participants