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

173
Visualizações
What is the best way to write different css or scss for the same component?

Imagine that I have a complex component like a dropdown menu and I want it to have some custom styles when I use it in different places. Not only colors, but spacing and icons too.

If I'm using something like react, or vue, I could pass parameters to the props.

We can also use only scss, and there are a lot of ways of overwriting the styles:

.dropdown{
 width: 100px
}

//overwrite for my custom menu
.my-custom-menu{
 .dropdown{
   width: 120px;
  }
}

Or if using something like BEM, I could even make the main class name a variable and change it:

.dropdown{
  &__container{
    width: 100px;
  }
}

//custom
.other-dropdown{
 &__container{
   width: 120px;
  }
}

What is the best way? Are there other ways of doing this?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Make your component re-usable. You just add style for modifed states or context like dark, light big, small** etc.

.dropdown{
  &__container{
    width: 100px;
  }
}

//custom

.dropdown{
 
 &.dark {
  color: dark;
 }
 
 
 &.light {
  color: white;
 }
  
}

And this is work for all components so far.

you had:

--dropdown
--dropdown__container
--container-small
--container-big
about 4 years ago · Santiago Trujillo Relatório
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