I am trying to create a card with image on the left and the card content on the right using flex in NEXTJS and Tailwind CSS.
So, I am trying to have that image to be responsive.
<div className="block">
<Image
src={item.cover}
alt="Picture of the something nice"
width={200}
height={200}
layout="responsive"
quality={65}
/>
</div>
I have this setup for the image in a card.
<div className="container max-w-3xl text-white bg-card flex rounded space-x-5">
<div className="block">
<Image
src={item.cover}
alt="Picture of the something nice"
width={200}
height={200}
layout="responsive"
quality={65}
/>
</div>
<section className="flex flex-col mt-2">
<h1 className="capitalize text-lg font-semibold">{item.title}</h1>
<h2>{item.alias}</h2>
<h3>{item.artist}</h3>
<h3>{item.author}</h3>
<p>{item.description}</p>
</section>
</div>
The image disappears.
So, I have tried using
layout=fill
. The image shows but it is not taking the cover image effect as expected.
Here is the <Image/>
with layout=fill
and objectFit=cover
.
<div className="block w-36 relative">
<Image
src={
'https://images.unsplash.com/photo-1651786291345-d6e61ac65358?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1288&q=80'
}
alt="Picture of the something nice"
layout="fill"
objectFit="cover"
/>
</div>
Use this code to make your card. See in full page.
To use nextJs
Image
, then just try to wrap<Image>
with<div>
having same properties of<img>
in the below code and removeheight
andwidth
from<Image>
. Keeplayout =responsive
.