What's the best way of making a Next.js image component fit the parent size?

<Image
src="/images/other-img-1.jpg"
alt="Server image"
width={0}
height={0}
style={{ width: "100%", height: "100%" }}
/>
<Image
src="/images/other-img-1.jpg"
alt="Server image"
width={0}
height={0}
style={{ width: "100%", height: "100%" }}
/>
The width and height is necessary, though I can't set it to "100%" or something similar. How do I achieve this the best way possible without hard coding it?
Solution:
Use fill property
Jump to solution
6 Replies
kdiffin
kdiffin3w ago
Remove heigjt and width
Solution
kdiffin
kdiffin3w ago
Use fill property
kdiffin
kdiffin3w ago
And set the parent pisition to relative Optionally using object-cover could be useful
filyys
filyys3w ago
I'll check into that, thanks
kdiffin
kdiffin3w ago
any luck?
filyys
filyys3w ago
Yup, I had a few other issues in the meantime but I got it to work, thanks
Want results from more Discord servers?
Add your server