I want to pin evaluation of a CSS custom property to the element it's defined on #728
Replies: 4 comments 2 replies
-
@phloe Could you expand on this a bit more? I think I know where you’re coming from, but I want to make sure. |
Beta Was this translation helpful? Give feedback.
-
I want to be able to pin the evaluation of relative units in custom properties to the actual element I defined said custom property on. So every time it is used further down the node tree it will still look at the original element for evaluation (meaning it's stil live/dynamic - not just a static number). Does that help? Obviously this would require some new syntax - I haven't given that any thought :D |
Beta Was this translation helpful? Give feedback.
-
This seems like a job for Container Queries: https://developer.mozilla.org/en-US/blog/getting-started-with-css-container-queries/ |
Beta Was this translation helpful? Give feedback.
-
This is addressed by the .container {
container-type: inline-size;
}
.container__deeply-nested-element {
width: calc(100cqi / 3);
} You can view a demo on Codepen. |
Beta Was this translation helpful? Give feedback.
-
As an example, if I need to know the width of a container element to calculate the width of a deeply nested element:
Beta Was this translation helpful? Give feedback.
All reactions