I wonder if it is possible to have a CSS rule only applied if a css variable is defined. I've seen it is possible to define a default value, something like:
background-color: var(--bgColor, red);
But I don't think this will work in my project, Because what I would like is that when the variable is not defined to get the style that it will have if that line was not there in the CSS.
I added a codepen, to make it easier to understant what I am talking about:
https://codepen.io/xmorelll/pen/bGWLoaL
.container {
margin: 5px;
}
.content {
padding: 5px;
display: inline-block;
height: 100px;
width: 100px;
border: 1px solid black;
background-color: var(--bgColor) !important;
}
<div class="container">
<div class="content" style="background-color: blue">blue</div>
</div>
<div class="container">
<div class="content" style="background-color: yellow">yellow</div>
</div>
<div class="container" style="--bgColor: red">
<div class="content" style="background-color: green">red</div>
</div>
<div class="container">
<div class="content" style="--bgColor: green">green</div>
</div>