Next.js Discord

Discord Forum

Image component

Answered
Black carp posted this in #help-forum
Open in Discord
Avatar
Black carpOP
Hey, is there a way to keep my images responsive? From the research i've done the Image component sizes are passed in pixels. Is there a way to use other units or percentage (%)?
Answered by Arinji
those are old props
View full answer

30 Replies

Avatar
yes
use the fill property on the Image component
and wrap it with a div, with a position property of anything (just cant be static.. so relative etc)
then give that div any responsive css you want
the image will fill its parent div
@Black carp
Avatar
Black carpOP
That is exactly what I did and it did not work
Image
Image
Avatar
those are old props
Answer
Avatar
not sure why you didnt get warns
but its just fill={true}
or just fill
also objectFit is also old

style={{objectFit: "contain"}}
or just use className, upto you
Avatar
Black carpOP
Still incredibly big?
Image
Image
Image
My current resolution is 2K
Avatar
you forgot the position style
give position: relative to the .background class
Avatar
Black carpOP
It's a div, it has position: static on default no?
Avatar
static dosent work
i mentioned
and wrap it with a div, with a position property of anything (just cant be static.. so relative etc)
Avatar
Black carpOP
Oh I thought it said "can"
mb lol
Avatar
No worries
Fixed?
Avatar
Philippine Crocodile
What if you use aspect ratio?
Avatar
@Arinji Fixed?
Avatar
Black carpOP
Yeah
Avatar
@Black carp Yeah
Avatar
Awesome, mark an answer
Original message was deleted
Avatar
Boop