英文:
Next image not taking height
问题
我正在为下一个图像设置高度和宽度,但它没有设置高度为我要设置的值。它只将高度设置为100%,宽度正常工作。
我在使用Tailwind的类和之前的div没有与图像干扰的其他尺寸。
编辑:之前我在类名中使用了object-contain
,但没有任何效果。
英文:
I'm giving height and width to a next image, and it doesn't set the height to what I'm telling it to set. It just sets the height to 100% and the widht works fine.
I'm using tailwind for the classes and the divs before do not have any other sizes that interfere with the image
<Image
src={game.background_image}
alt={game.slug}
height="250"
width="450"
priority
className="rounded-t-2xl"
/>
EDIT: I had object-contain before in the classname but it didn't do anything
答案1
得分: 2
将您的<Image />包装在一个div中,像这样:
<div>
<Image
src={game.background_image}
alt={game.slug}
height="250"
width="450"
priority
className=" rounded-t-2xl"
/>
</div>
这将使在Next Image中设置的高度和宽度按预期工作。
英文:
Wrap your <Image /> in a div like so:
<div>
<Image
src={game.background_image}
alt={game.slug}
height="250"
width="450"
priority
className=" rounded-t-2xl"
/>
</div>
This will make the height and width set inside the Next Image work as intended.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论