I’m trying to set a background color for a different popup variant, but when I set a background value to something that has alpha value in it, but makes it transparent
the following css code
--color: 255, 144, 106, 0.18;
background: var(rgb(--color))
Is there’s a way for me to retain the color without making the div non transparent?
Note: I can’t change the color token
tried changing the opacity of the parent or even setting a background on it, but no result
4
Answers
The alpha value changes the opacity of the color. There is not much you can do about it except changing the alpha value itself. If your div is completely transparent, you could try to add
opacity: 1;
to the styling.Edit: I just saw the example which makes my answer kind of invalid. If you can’t change the color variable, your only option is either to live with it or try to overwrite the color with a different opacity by creating a new variable.
I see that you tagged this with javascript.
One hack that isn’t as pretty as actually changing the code is using javascript to change it.
Its not perfect and might flicker on load etc.. But your system has put you in a difficult place without having access to change certain things.
I really advice you to update the way you handle the colors. If you don’t want transparency, don’t set it.
In this particular case, you can hack it by using multiple layers where the bottom one is black or white depending on your need:
The correct syntax for RGBA values in CSS custom properties is as follows:
Notice that I’ve used rgba() instead of rgb(), and this should correctly set the background color with the specified alpha (opacity) value. Using the rgba() function explicitly states that you are defining a color with an alpha channel, which should prevent the background from being fully transparent.
Here’s the corrected CSS code: