In my SVG, there are several rectangles that change their fill color in a gradient effect as they move down the SVG. Users have the option to choose a solid fill color to customize their experience, which replaces the gradient color of the rectangles. I am accomplishing this using CSS variables.
However, I am facing an issue where I want the rectangles to default back to the original fill color defined in the SVG if no theme color is chosen by the user. In such cases, the CSS variable is set to ''
, making it invalid. Unlike other elements where I can set a default value for fallback, each rectangle in the SVG has a unique fill color. When I tried removing the default value, the fill reverted to its initial CSS value, which is transparent.
For example, if I have a rectangle with the code
<rect id="rect" fill="#000000" x="0" y="0" width="200" height="50" rx="6"></rect>
and the following CSS: rect { fill: var(--preview-primary); }
, I would expect the rectangle to be black when --preview-primary
is invalid, but instead, it appears transparent.
I am looking for a solution to address this issue. Any help would be greatly appreciated. Thank you.