Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

139
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda