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
kdiffin3mo ago
Remove heigjt and width
Solution
kdiffin
kdiffin3mo ago
Use fill property
kdiffin
kdiffin3mo ago
And set the parent pisition to relative Optionally using object-cover could be useful
filyys
filyysOP3mo ago
I'll check into that, thanks
kdiffin
kdiffin3mo ago
any luck?
filyys
filyysOP3mo 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