I get 2 different output for the code below. It should give the same output since default value should be taken by the css variable. Below is the code where I commented passing span
a value, since it has a default value in the var declaration . Uncommenting the value assignment line give different output. Looking for a explanation of what is happening.
Here is the code pen with commented code - https://codepen.io/skandasoft/pen/MWjoMZe
and here is with uncommented - https://codepen.io/skandasoft/pen/VwKWJqd
Bootstrappy Grid with CSS Variables!<body>
<div class="grid">
<div class="item">1</div>
<div class="item" style="--span: 7">
<div class="grid" style="--cols: 2">
<div class="item">1</div>
<div class="item">2</div>
</div>
</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
<style>
.grid {
display: grid;
gap: 10px;
grid-template-columns: repeat(var(--cols, 10), minmax(0, 1fr));
}
.item {
/* --span: 1; */
grid-column: span var(--span, 1); /**-span has a default value of 1 **/
background-color: yellow;
padding:10px;
}
</style>
</body>