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

133
Vistas
Prepend static parent class before Styled-Component classes

I am trying to figure out something with our Styled Component App. For the context, we create a app that will live inside a website that already has its own global style sheet. The problem is, when we plug in the application within the website, plenty of our generated style is overridden by the global stylesheet, which uses a parent class to wrap some elements.

Generated HTML

<div class="PARENT_CLASS">
  <div id="PARENT_ID">
    <div id="MY_APP">
      <div class="sc-gtsrHT ddDIoa test-wrapper">
        <a href="/">Click me</a>
      </div>
    </div>
  </div>  
</div>

Generated CSS

/* WEBSITE STYLE */
.PARENT_CLASS #PARENT_ID a {
  color: #0ae;
}

/* SC GENERATED */
.ddDIoa a {
  color: red;
}

React Javascript

const TestWrapper = styled.div`
  a {
    color: red;
  }
`;

const A = styled.a`
  color: red;
`;

const Content = () => (
  <TestWrapper className="test-wrapper">
    <A href="/">Click me</A>
  </TestWrapper>
);

Is there way to prepend the static classes (.PARENT_CLASS #PARENT_ID) to all generated classes by Styled Component without having to do on every single Component I create.

Thx

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This problem is answered here in styled component documentation. Highlighted Documentation

This solution uses babel-plugin-styled-components-css-namespace to prepend classes/ids to all your styled component components.

about 4 years ago · Juan Pablo Isaza Denunciar
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