Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

621
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda