You can get around the problem by using a mediator: CSS variables , which are the only data that is “outside” the curly braces.
If the parent width is also dynamic or dependent on a different value, use a different variable for this. As an example, so you can see the syntax, it will look something like this:
:root { --hex-parent-height: 10px; } .hexagon.parent { width: var(--hex-parent-height); } .hexagon { height: 100%; width: calc(100% * var(--hex-parent-height)); display: inline-block; }
CSS variables have two types of scope: global and local. Local variables will only work logically in the same selector, but global variables are the same in all of your CSS. Declaring one or more variables globally is done through the root block, as shown in the code example.
Getting the value of a variable, as you can see, is as simple as using the CSS var () function, which, if you don’t know, has a very good backup function .
For example, if you needed --hex-parent-height set --hex-parent-height and something went wrong, and --hex-parent-height , you can insert a default value to minimize damage, for example : var(--hex-parent-height, 10px)
Carles alcolea
source share