【问题标题】:NextJS Image component not responding to my inline css inside itNextJS Image 组件没有响应我的内联 CSS
【发布时间】:2021-05-30 22:43:34
【问题描述】:

为什么 NextJS 中的 Image 组件内部的样式不允许我操作我的图像。 我错过了什么吗?

<Image className={styles.bg}
        style={{ transform: `translateY(${offset * 0.5}px)` }}
        src="/../public/bg.jpg"
        // width={2049}
        // height={2049}
        // objectFit="cover"
        layout="fill"
        quality={100}
      />

【问题讨论】:

  • translateY(${offset * 0.5}px) }} src="/../public/bg.jpg" // width={2049} // height={2049} // objectFit="cover" layout="fill" quality={100} />
  • 不能在next/image组件中直接使用style。你必须使用 className 属性。

标签: javascript reactjs next.js nextjs-image


【解决方案1】:

组件上的其他属性将被传递给底层的 img 元素,但以下情况除外:

风格。请改用 className。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-16
  • 1970-01-01
  • 1970-01-01
  • 2015-11-29
  • 2021-09-12
  • 1970-01-01
  • 2021-10-20
相关资源
最近更新 更多