I prefer to use scss varibles but they can not be changed 'runtime'. For example if I have a scss variable $color: #000; and I want to change its value like this then it wont work:
html{
background-color: $color;
&.orange{
$color: orange;
}
}
On the other hand when I use css variables it will:
:root{
--color: #000;
}
html{
background-color: var(--color);
&.orange{
--color: orange;
}
}
I know the reason why but alone I could not solve this problem. So my question: Is it possible to store css var in scss var somehow?
What I have already tried:
:root{
--color: #000;
}
$color: var(--color);
$color: ${'var(--color)'};
$color: "var(--color)";
any idea how to solve this without custom functions?
$color: 'var(--color)';
then you use it like:.colour { color: $color; }
. For your orange override, you cannot use the sass var, you would override it as normal:&.orange{ --color: orange; }
} – Pete$color: unquote('var(--color)');
and now it works. Thanks! Could you please write a summary about this as an answer? :) – Bálint Réthyvar(--color)
anywhere in your SCSS where you need the dynamic value, instead of $color. – Martin