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

183
Visualizações
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 Respostas
Responde à pergunta

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 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