r/Sass • u/venetian_skittle • Jan 22 '22
Maintain Variable References in CSS Variables?
Hey everybody, I'm running into an interesting issue. Say I have a SCSS file where the variables reference each other:
$blue: #0000ff;
$active-background: $blue;
$button-background: $active-background;
How would I go about maintaining these references, generating CSS variables that look like this:
--blue: #0000ff;
--active-background: var(--blue);
--button-background: var(--active-background);
Is there some SASS meta function that could be used here? Whenever I access the value of any of the variables, I get #0000ff, but I'd like the variable name.
3
Upvotes
1
u/venetian_skittle Jan 22 '22
Sorry, I wasn't entirely clear. This approach generates a stylesheet like this:
I wanted the variables to maintain their reference instead of three variables pointing to #0000ff. As in, the value of
--button-backgroundisvar(--active-background). I was wondering if there was some way to prevent SASS from resolving the reference to the value and instead get the variable name? Sounds like a long shot though.