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

182
Vistas
Is there a way of styling images using styled components in ReactJS?

I have just started working with Styled Components and I 've been running into problems with styling images and I don't mean background images.

export const PrimaryImage = styled.img`
width: 40%;
border-radius: 5px;
height: 50%;
`;

That is what I typed but it won't run of course. So I decided to just wrap the image in a div and style the div

export const PrimaryImage = styled.div`
width: 40%;
border-radius: 5px;
height: 50%;
`;

The div responds but the image doesn't. Is there a way I can target the image itself without having to use a CSS stylesheet?

Thanks in advance

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

0

I've finally figured it out After your div's CSS, you just type in the ampersand character (&) and then the image you are trying to style like the way it's shown below

NOTE: The image has to be inside the specific div before you can access it though

That was how I was able to style the image using Styled Components in ReactJS

I hope this helps anybody that may have this problem and if there's a better way, I'd love to learn

export const PrimaryImage = styled.div`
width: 40%;
border-radius: 5px;
height: 50%;

& > img {
width: 100%;
height: 50%
border-radius: 5px;
`;

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