下一张图未设置高度。

huangapple go评论61阅读模式
英文:

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"
/>

problem

EDIT: I had object-contain before in the classname but it didn't do anything

答案1

得分: 2

将您的<Image />包装在一个div中,像这样:

&lt;div&gt;
    &lt;Image
        src={game.background_image}
        alt={game.slug}
        height=&quot;250&quot;
        width=&quot;450&quot;
        priority
        className=&quot; rounded-t-2xl&quot;
    /&gt;
&lt;/div&gt;

这将使在Next Image中设置的高度和宽度按预期工作。

英文:

Wrap your <Image /> in a div like so:

&lt;div&gt;
    &lt;Image
        src={game.background_image}
        alt={game.slug}
        height=&quot;250&quot;
        width=&quot;450&quot;
        priority
        className=&quot; rounded-t-2xl&quot;
    /&gt;
&lt;/div&gt;

This will make the height and width set inside the Next Image work as intended.

huangapple
  • 本文由 发表于 2023年6月30日 03:31:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76584112.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定