Does anyone know how to style images using Styled Components in React?
I can't seem to find a solution anywhere

For further actions, you may consider blocking this person and/or reporting abuse
Does anyone know how to style images using Styled Components in React?
I can't seem to find a solution anywhere
For further actions, you may consider blocking this person and/or reporting abuse
Timeless DEV post...
The most used technology by developers is not Javascript.
It's not Python or HTML.
It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.
I'm talking about Git and version control of course.
Ben Halpern -
Technophile -
Josefine Schfr -
Vicente Antonio G. Reyes -
Once suspended, anni will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, anni will be able to comment and publish posts again.
Once unpublished, all posts by anni will become hidden and only accessible to themselves.
If anni is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Anietie Brownson.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag anni:
Unflagging anni will restore default visibility to their posts.
Top comments (7)
I'm absolutely terrible with CSS, but maybe something like this will work?
codepen.io/Mykezero/pen/jOaajZK
You can also place the styled component in a separate file and export it to share the style as well. Hopefully this helps! ^^
First, you can style your component, using a specified class, in a css file, and import the file into your the App.js file. That can work too.
Thank you all for your suggestions. I figured out a way of doing it without using CSS
I wrapped the image in a div:
export const PrimaryImage = styled.div`
width: 80%;
Then I specifically targeted the image like this:
& > img {
width: 100%;
height: max-content;
border-radius: 15px;
}
`;
I did this in an image.elements.js file and then imported it in my main JS file
Problem solved!
What are you trying to achieve?
Something like this is how you'd make a styled img tag.
Styled-components just helps you write CSS in JS. It's not a component library, better find a React/JavaScript component that handle images properly (lazy loading, placeholder, caching, responsive, multiple sizes, etc). next/image or lazysizes are good start. Then wrap that image component with style-components to play well with your codebase.
First, you can style your component, using a specified class, in a scss / css file, and import the file into your the App.js file. That can work too.
i am java developer for 10 years and just 2 years ago i learned css haha