Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!