【发布时间】:2021-07-13 01:49:30
【问题描述】:
我正在尝试将我的标准 <img/> 更改为 NextJS <Image/>,但我找不到我的图像无法正确呈现的原因。
这是基础标签
<div className=" mx-auto sm:w-9/12 lg:w-7/12 xl:w-8/12">
<img
className="object-fill rounded-md mx-auto sm:w-9/12 lg:w-full xl:w-8/12"
src={img}
alt="something"
/>
</div>
效果很好
在使用 NextJS 图像时,它不能正常工作
<div className=" mx-auto sm:w-9/12 lg:w-7/12 xl:w-8/12">
<Image
src={img}
layout="fill"
objectFit="contain"
alt="something"
className="rounded-md mx-auto w-full"
></Image>
</div>
我可以看到<Image/> 的外部 div 本身占用了整个 div 的宽度(文本 + 图像),因为 <Image/> 的父 div 显然没有宽度或高度,而它有 w -7 月 12 日。
【问题讨论】:
标签: next.js nextjs-image