I have a flex
box and I also want it to be hidden (display: none !important
) only if a variable is set.
.d-flex {
display: flex; /*Set by Bootstrap library*/
}
.my-item {
display: var(--display); /*Should only apply if --display is set*/
}
.container.hide-items {
--display: none !important;
}
<div class="container">
<div class="d-flex my-item">Flexbox 1 (not hidden)</div>
<div class="d-flex my-item">Flexbox 2 (not hidden)</div>
</div>
<div class="container hide-items">
<div class="d-flex my-item">Flexbox 1 (hidden)</div>
<div class="d-flex my-item">Flexbox 2 (hidden)</div>
</div>
The above code only works when hide-items
exists but when --display
is undefined, the browser just falls back into (probably) inline
. I know var()
accepts fallback values but I do not know how to set it so the element stays to whatever it was set before (in this case flex
), I have tried unset
or initial
but they don't get their flex
value back. Is this possible?