Responsive fix for the Next.js Image component
Sachin Tiwari
NextJS, React, Javascript, CSS, HTML, GraphQL - Sr. React/Frontend/UI Developer
=> First, we have to add the wrapping item with the class image-container and image class to Image component.
<div className={'image-container'}>
<Image src={path} layout="fill" className={'image'} />
</div>
=> you need to add below styling
.image-container {
? ? width: 100%;
}
.image-container > div {
? ? position: unset !important;
}
.image-container .image {
? ? object-fit: contain;
? ? width: 100% !important;
? ? position: relative !important;
? ? height: unset !important;
}