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

140
Vistas
Applying theme changing mechanism at run-time with css var

I'd like to use css var() in order to change themes on my website at run-time. Every time a user selects a theme, I import the correspondent file into the page. But once I import an already imported css file, the style on the page doesn't get updated. I tried to solved it by removing the former css theme file from the tag, but it doesn't appear there as a tag with an href attribute, but rather as a tag with no possible way to query it and remove it.

For example:

Main.css:

.header {
   background: var(--primary-color);
}

ThemeA.css

:root {
--primary-color: red;
}

ThemeB.css

:root {
--primary-color: blue;
}

Is there any way that I can solve it, or do I have to seek for an alternative solution? and if so, which solution is most suitable?

Edit

I do the import inside a react component. Here's an essence of how I do it:

export const MyComponent = ({theme) => {
   import(`../styles/${theme}.css`);
   /* rest of the code */
})
about 4 years ago · Juan Pablo Isaza
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