IssueRaiser

[css-values-5] inherit() function: like var() for parent value, for any property

[Edit: We've now defined 'inherit()', but only for custom properties. The issue is left open to track the fuller feature.] ------- We've declined numerous author requests to extend `var()` to arbitrary properties, due to the potential for cycles and how expensive cycle detection would be in the general case. However, providing a way to get the **parent** or **inherited** value of any property does not cause cycles and still helps with a ton of use cases. ## Use cases ### Custom property value that depends on parent value Generic `--depth` ([1](https://twitter.com/plinss/status/1350550362168545280), [2](https://twitter.com/kizmarh/status/1350937936804667394)) ```css * { --depth: calc(inherit(--depth, 0) + 1); } ``` See also: https://github.com/w3c/csswg-drafts/issues/1962 ### Font metrics relative to parent - #2690 - #2764 ```css strong { font-weight: clamp(600, 1.2 * inherit(font-weight), 999); } ``` And any other numerical typographic metric that can be specified in CSS, e.g. `font-stretch`, `font-style` (for variable fonts) etc ### Many of the `currentBackgroundColor` use cases https://github.com/w3c/csswg-drafts/issues/5292 While this does not address all use cases (since it would only provide an ancestor background color), it does address quite a few, and offers a workaround for others. ### Matching nested radii https://github.com/w3c/csswg-drafts/issues/7707 | `inherit` | `inherit()` + calc | |--------|--------| | <img width="377" alt="Screen Shot 202

Posted by LeaVerou on Jul 3, 2018, 12:28 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

pricing (Software)

[css-values-5] inherit() function: like var() for parent value, for any property

LeaVerouJul 3, 2018, 12:28 AM

[Edit: We've now defined 'inherit()', but only for custom properties. The issue is left open to track the fuller feature.] ------- We've declined numerous author requests to extend `var()` to arbitrary properties, due to the potential for cycles and how expensive cycle detection would be in the general case. However, providing a way to get the **parent** or **inherited** value of any property does not cause cycles and still helps with a ton of use cases. ## Use cases ### Custom property value that depends on parent value Generic `--depth` ([1](https://twitter.com/plinss/status/1350550362168545280), [2](https://twitter.com/kizmarh/status/1350937936804667394)) ```css * { --depth: calc(inherit(--depth, 0) + 1); } ``` See also: https://github.com/w3c/csswg-drafts/issues/1962 ### Font metrics relative to parent - #2690 - #2764 ```css strong { font-weight: clamp(600, 1.2 * inherit(font-weight), 999); } ``` And any other numerical typographic metric that can be specified in CSS, e.g. `font-stretch`, `font-style` (for variable fonts) etc ### Many of the `currentBackgroundColor` use cases https://github.com/w3c/csswg-drafts/issues/5292 While this does not address all use cases (since it would only provide an ancestor background color), it does address quite a few, and offers a workaround for others. ### Matching nested radii https://github.com/w3c/csswg-drafts/issues/7707 | `inherit` | `inherit()` + calc | |--------|--------| | <img width="377" alt="Screen Shot 202

Comments (0)

No comments yet. Start the discussion.

Comment on this issue