What I would like to do is make the #grid
height
160% of the #grid
width
via calc(var(--grid-item-width) * 1.6)
, but it appears that --grid-item-width
is being treated as a percentage of the viewport width instead of a pixel value.
The height of #grid
is much larger than 160% of its width as can be seen in the screenshot below.
:root {
--gap: 26px;
--grid-item-width: calc(100% - calc(var(--gap) * 4));
}
#grid {
width: 100%;
height: var(--grid-item-width); /* does not match */
overflow-x: auto;
display: grid;
grid-gap: var(--gap);
grid-auto-flow: column;
grid-auto-columns: var(--grid-item-width); /* does not match */
}
When I print the value of --grid-item-width
to console, it returns calc(100% - calc( 26px * 4))
, which obviously does not help.
One of the notes about calc()
on MDN states:
Math expressions involving percentages for widths and heights on table columns, table column groups, table rows, table row groups, and table cells in both auto and fixed layout tables may be treated as if auto had been specified.
Is this why calc(var(--grid-item-width) * 1.6)
has an unexpected output in this situation?