Skip to content

[css-variables] define custom property based on parent's (inherited) value #1962

Open
@dubrowsky

Description

@dubrowsky

According to the Resolving Dependency Cycles section of the spec it's not possible to use var(--property) while defining the --property itself.

Here's an illustration of the problem I'd like to solve:

.table {
    width: 60vw;
    --width: 60vw;
}

.column {
    width: 25%;
   // should be (60vw / 4) = 15vw
    --width: calc( var(--width) / 4);
}

.something-inside-the-column {
     // should be (60vw / 4) * 0.1 = 6vw
     font-size: calc( var(--width) * 0.1 ); 
}

So I'd like to use the inherited value if the own is not yet defined. If this behavior is hard to implement, maybe the specification can introduce another function to use inherited values explicitly, something like this:

    --width: calc( inherited-var(--width) * 0.1 );

The solution suggested here (just use two different props) is not the answer, because I want my components to be "context-agnostic". Please tell me if my case is not clear enough, I'll try to provide some better example then. Thank you!

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