【问题标题】:(Next.js) How can I change the color of SVG in next/image?(Next.js) 如何在 next/image 中更改 SVG 的颜色?
【发布时间】:2021-04-16 23:25:22
【问题描述】:
import Image from 'next/image'

...

<Image src="/emotion.svg" alt="emtion" width={50} height={50} />

我想更改 next/image 中的 SVG 颜色。

但在 CSS 中,

img {
  fill="#ffffff"
}

不工作。

我该如何解决这个问题?

【问题讨论】:

  • 您需要定位正确的 SVG 元素以应用 fill 属性。将其应用于 &lt;img&gt; 不会有任何效果。

标签: css reactjs next.js styled-components nextjs-image


【解决方案1】:

我建议你不要直接使用svg文件,而是使用Playground SVG(https://react-svgr.com/playground/),将文件转换为JS,然后你可以通过props改变颜色和其他东西。

【讨论】:

  • 感谢您的建议!我使用 svg 更改了方法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-23
  • 1970-01-01
  • 2022-11-17
  • 2022-07-11
  • 2022-01-07
  • 2020-10-31
相关资源
最近更新 更多