1

In css i can declare variable:

:root {
  --main-bg-color: pink;
}

And then using javascript to reassign value:

document.body.style.setProperty('--main-bg-color', '#5A8795')

How to make something similar with Sass variables?

$main-bg-color: pink;

3 Answers 3

1

This is unfortunately not possible. You can however achieve what you want by using this technique. And then edit it in the final step via Js.

$var: /**/;

--variable: #{$var};

Hope this is at least a little helpful ;'D

Sign up to request clarification or add additional context in comments.

1 Comment

@Qui-GonJinn, Yeah! Not that long ago, that I actually first stumbled upon this.
1

@Simplicius is right, You can't. Because SASS is a CSS preprocessor, that means that all SASS specific information disapears when you compile it to CSS.

Comments

0

Try this:

$main: pink;

:root {
  --main: #{$main}
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.