Reputation: 20654
According to MDN, the var
function accepts multiple fallbacks. But I am unable to get them to work.
I tried the following code on Chrome, Firefox and Safari. The background-color
for .demo3
is transparent on all the above browsers.
Is it an error with the code, or is it because the browsers have not implemented variable fallback?
:root {
--my-var: red;
}
.demo1 {
background-color: var(--my-var);
}
.demo2 {
background-color: var(--my-background, pink);
}
.demo3 {
background-color: var(--my-background, --my-var, pink);
}
<div class="demo1">No fallback</div>
<div class="demo2">Single fallback</div>
<div class="demo3">Multiple fallbacks</div>
Upvotes: 5
Views: 2382
Reputation: 602
For multiple fallbacks try: background-color: var(--my-background, var(--my-var, pink));
Upvotes: 16