I'm using a simple grid, where the amount of columns can be configured/overwritten via a CSS variable.
.grid {
display: grid;
grid-template-columns: repeat(var(--grid-columns, 1), 1fr);
}
// Mixin for tablet media query
@include tablet {
.grid {
--grid-columns: 2;
}
}
// Mixin for tablet media query
@include desktop {
.grid {
--grid-columns: 4;
}
}
Above is a simplified example.
I also have a class that can be used on a "cell", to note whether it is full width or two cells wide (span-half).
@include desktop {
.span {
&-full {
grid-column: 1 / -1;
}
&-half {
grid-column: span calc(var(--grid-columns) / 2);
// or grid-column: auto / span calc(var(--grid-columns) / 2);
}
}
}
I use a .span-half to create a cell that spans half of the column size set by the --grid-columns variable.
However, this calculation does not work in Chrome or Safari. Firefox renders .span-half correctly (eg. a cell that spans 2 columns in desktop). I see no "invalid value property" in Dev Tools.
Here's a Codepen https://codepen.io/Bregt/pen/oNbWvzx
I have no clue. What am I missing?