-
I tried to define my image like this: <Image
src={props.image.url}
alt="Picture of the author"
width={props.image.width}
height={props.image.height}
className="card__image"
/>
<style jsx>{`
.card__image {
width: 100%;
}
`}</style> But that won't work. The image is only displayed at full size. What should we do when we wan't a fluid width for the images, to use in a responsive grid etc? |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 33 replies
-
I think your question overlaps with the one I recently made. There's a link to where the styling is added in the next/image component. |
Beta Was this translation helpful? Give feedback.
-
In Version 10.0.1 they added the |
Beta Was this translation helpful? Give feedback.
-
In 2023, every above solution is deprecated, use below
|
Beta Was this translation helpful? Give feedback.
-
For me this works with tailwind: <div className="relative h-20 w-full">
<Image
src={url}
fill
/>
</div> Ofcourse you can use NOTE: <img
style="position:absolute;height:100%;width:100%;left:0;top:0;right:0;bottom:0;color:transparent"
...
/> |
Beta Was this translation helpful? Give feedback.
-
Why the freaking hell is it necessary to use Image tag only . As a developer, we must have freedom to use img or figure tag based on requirements. It seems next js always limiting choice for developers for its egoistic approaches |
Beta Was this translation helpful? Give feedback.
-
I can see that now the Image component has given the choice to pass only pure numbers for width and height. Even if it is optional, without passing height and width, it gives the error. |
Beta Was this translation helpful? Give feedback.
-
Anyone wondering about it, you just set width to 100% on the className. I am using tailwind and just simply <div className="relative rounded-md w-full borderTest">
<NextImage src={image} alt={imageAlt} className="rounded-t-md w-full" />
<CardBlogTop />
</div> |
Beta Was this translation helpful? Give feedback.
-
If use want use fill props you can work here: <div className="relative block h-[220px] w-full">
<Image src={image} alt="image" fill style={{ objectFit: 'cover' }} />
</div> |
Beta Was this translation helpful? Give feedback.
-
All of the above solutions don't work. It's working for me:
|
Beta Was this translation helpful? Give feedback.
-
now nextJS official document gives an answer in 《Responsive Image》 chapter, here is the link
and you can wrap it using a parent |
Beta Was this translation helpful? Give feedback.
In Version 10.0.1 they added the
layout
prop to the image component. Setting it toresponsive
sets the css max-/min-width to 100%. Maybe this works for your usecase.