Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

611
Views
SASS variables to CSS variables (gulp-sass)

I want to change with javascript some SASS/CSS variables to change the color of multiple elements. ๐Ÿ˜…

How I can send SASS variables to CSS as variables? I tryed it like in the documentation of Sass, but it gives me an error, on compiling the CSS.

Here the Error:

Error in plugin "sass" Message:
dev\sass\_settings.sass Error: Invalid CSS after "$primary-color: #ff2aad;": 
expected 1 selector or at-rule, was "root: {"
    on line 5 of dev/sass/_settings.sass
    from line 1 of dev/sass/style.sass
    $primary-color: #ff2aad;

Here my SASS code:

$primary-color: #ff2aad

:root
  --primary-color: #{$primary-color}

Im using an NodeJS enviroment with an gulpfile.js. My gulp-sass version is 4.1.0

It passes if I remove this part:

:root
      --primary-color: #{$primary-color}

Maybe it exist an better way to manipulate SASS variables with javascript. If someone have an idea or documentation this would really help me ๐Ÿ˜Š


Update / Solution:

I found out by using an CSS to SASS Converter that I have to add an \ before the :root Element

The Solution looks like this in SASS:

$primary_color: #ff2aad

\:root
  --primary_color: #{$primary_color}

h1 
  color: var(primary_color: #ff2aad);

I didn't found any documentation about this but it seams to work perfectly fine without error or issues. ๐Ÿ˜Š

Thanks on all that tryed to help. You Rock ๐Ÿค˜

over 4 years ago ยท Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!