Skip to content

[css-values] Idea to make "var() for regular properties" implementable #9454

Open
@LeaVerou

Description

@LeaVerou

The discussion in #7707 gave me an idea. We have this frequent author request for var() to work with regular properties, which we cannot do because cycles (though we have resolved for an ancestor version, see #2864 ).
However, the issues only occur for a small subset of properties, different for each property. For many properties any property would be fine except themselves (and any of their longhands).

So what if we could simply restrict the dependency graph by restricting which properties are allowed based on the property var() is used on?

For example, the use case in #7707 in the simple case (single radii, single box model metrics) can be done like:

border-radius: calc(
	inherit(border-radius) 
	- inherit(padding) - inherit(border-width) 
	- var(margin)
);

(The complex case would simply require four of these)

Some cycle detection would still be needed, to detect cycles with more than 1 step, like:

background: var(color);
color: var(background);

We'd still need to figure out serialization, but we need to do that for inherit() anyway.

Yes, this requires high effort, and is a very complex feature, however there is also very high value. This together with inherit() would unlock a ton of use cases (I can list them if non-obvious, but wanted to check feasibility first).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions