Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use CSS variables in SASS [scale-color] function?

Similar question but need this help, I want to change the overall website color using two css variables, --color-primary and --color-secondary, because I have two color option in the admin dashboard. Admin can change the color for every listed company according to their branding.

So I have 5 colors, Two are dark and other three are light from same color family.

I want to convert the dark to lighten color in some places. Here is my code which is not working. Codepen

:root {
--color-primary: blue;
--color-secondary: red;
}

$primary : var(--color-primary);

//convert to light form primary color
$bg-color : scale-color($primary, $lightness:80%);

.logo{
  background: $bg-color;
  height: 100px;
  width:100px;
} 

Does anybody know how can I fix this issue? Or is it just not possible? Thanks in advance.

like image 240
Figar Ali Avatar asked Oct 31 '25 17:10

Figar Ali


1 Answers

It cannot take the variable that assigned from css root selecter as an argument. But you can do this as folows:

$primary:blue;
$bg-color:lighten($primary,80%);
or $bg-color:scale-color($primary,$lightness:80%);
.logo{
    background: $bg-color;
}

<////EDITED///> This web site may has a solution https://codyhouse.co/blog/post/how-to-combine-sass-color-functions-and-css-variables

like image 50
Dawit Tesfamariam Avatar answered Nov 03 '25 07:11

Dawit Tesfamariam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!