Re: [csswg-drafts] [css-values-4] inherit() function: like var() for parent value, for any property (#2864)

@Loirooriol 

> > Does it return the parent value regardless of what it is, or walk up ancestors until it finds a value or hit the root?
> 
> In general I don't think walking ancestors makes much sense for non-inherited properties. Even for inherited ones it may be undesirable. So I would just return the parent value.

I suppose that's more predictable (and probably more performant and easier to implement). After all, if one wants the value from a specific ancestor, there's an easy workaround:

```css
/* Swap background & foreground in descendants use case: */
.container > * {
 --container-background: inherit(background-color);
}

.container * {
 color: var(--container-background);
 background: inherit(color);
}
```

> > It should probably have a fallback, just like `var()`. The fallback would apply when the returned value is `initial`.
> 
> But using the fallback for initial values would be inconsistent with `var()` and `env()`. I think the fallback should be used when the serialization of the computed value is the empty string (like a guaranteed-invalid value, or a shorthand that can't represent the values of its longhands). IMO custom behaviors for specific values should be achieved with conditionals (#5624).

The fallback for `var(--foo)` **is** applied when `--foo` is `initial` ([demo](https://dabblet.com/gist/b49604259b2765fec0966ba649dad8c8) [spec](https://www.w3.org/TR/css-variables/#invalid-variables)). I agree with your reasoning however, especially since this allows shorthands to be used, which is really important.

> 
> > Can shorthands be referenced? If so, what do they return?
> 
> If this feature is based on serializations, then it doesn't seem problematic to me. Just try to serialize the shorthand, and return that in case of success, or empty string otherwise. When reparsed, empty string can be treated as a guaranteed-invalid value, and use the fallback value if provided, or become IACVT otherwise.

I really like this. 💯 


-- 
GitHub Notification of comment by LeaVerou
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/2864#issuecomment-762316044 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 18 January 2021 15:22:10 UTC