I'm currently building a web app in Angular, and have stumbled onto some very odd differences in the final color that is being outputted. The premise is this:
I have a global color variable in :host of app.component.scss
--primary-color-in-host: rgba(38, 50, 56, 0.9)
I want to use this color variable across my app in various components, and able to do so successfully using:
var(--primary-color-in-host)
.
No problem there. However, I would also like to occasionally apply an opacity to this color. This is where the problem appears.
Normally, if you declare a variable locally in the component's scss $primary-color-local: rgba(38, 50, 56, 0.9)
, you can successfully apply opacity to the variable like so: color:rgba($primary-color-local, .5)
. But because I've declared the variable globally in :host(see above), the opacity does not apply when I try to apply it using rgba(var(--primary-color-in-host), .5)
. I just get the color, but not the opacity!
Naturally, I could just re-declare this color in each component's .scss, but would like to avoid doing so (for obvious reasons). But before I can even begin to tackle the problem, I need to understand what is going on underneath the surface. Why is it working locally, but not when the color is being pulled from :host?