如何在nextjs中删除这个图像的背景?

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

How to remove this this image Background in nextjs

问题

I will only provide the translated content without the code. Here's the translation of the text you provided:

这是添加的图片,但在 Nextjs 中呈现时会自动添加额外的内容。

这是 div 内部的代码,我只需要图片,不需要额外的方形内容。

英文:

如何在nextjs中删除这个图像的背景?

This image is added but when it is rendered in Nextjs it automatically adds the extra content.

<div className="flex flex-col items-start justify-start rounded-3xl p-4 bg-boxi w-1/3">
  <div className="mb-4">
    <Image
      src={ProfilePic}
      alt=""
      className="w-1/2 h-auto hover:drop-shadow-image"
    />
  </div>
  <div className="w-full flex flex-col items-start">
    <p className="text-lg font-semibold text-light mb-1">------</p>
    <p className="text-base font-medium text-light mb-1">-------</p>
    <p className="text-sm font-medium text-light">example@gmail.com</p>
  </div>
</div>

This is the code inside the div, I need only the image not the extra square content.

答案1

得分: 0

Next/Image

> 这个 next/image 组件使用浏览器本机的延迟加载

这对于 SEO 是一个良好的实践,并且专门设计用于防止 CLS (累积布局位移),因此需要提供显式的 widthheight 属性进行布局管理。示例:

<Image
    src={ProfilePic}
    alt=""
    width={500}
    height={500}
    className="w-1/2 h-auto hover:drop-shadow-image"
/>

或者,另一种方法是将这些大小属性提升到它们的容器中。示例:

<div class="container relative h-10 w-10">
    <Image
        src={ProfilePic}
        alt=""
        fill
        size"30vw" 
        className="object-contain hover:drop-shadow-image"
    />
</div>

有关此方法的更多信息,请参阅 fillsizes

在您的情况下,布局可以基于您提供的 html 组件的其他更高级的容器来呈现,这些容器具有显式的大小属性。因此,您可能会改为使用上述方法来进行清晰的布局管理。

英文:

Next/Image

> This next/image component uses browser native lazy loading

It's good practice for SEO and built to prevent CLS (Cumulative Layout Shift) so its needs to be provided explicit width and height properties for layout management. Example:

<Image
    src={ProfilePic}
    alt=""
    width={500}
    height={500}
    className="w-1/2 h-auto hover:drop-shadow-image"
/>

Alternatively, another approach for this case is to lift these size properties to their container. Example

<div class="container relative h-10 w-10">
    <Image
        src={ProfilePic}
        alt=""
        fill
        size"30vw" 
        className="object-contain hover:drop-shadow-image"
    />
</div>

For more on this approach fill and sizes.

In your case, the layout can render out may be based on other higher containers of the html component you provided, which have explicit size properties. So you might change to those approaches above for clean layout management.

huangapple
  • 本文由 发表于 2023年4月13日 17:21:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003786.html
匿名

发表评论

匿名网友

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

确定