如何将className添加到SVG React组件中
我现在正在为SVG React组件使用内联样式,因为如果我将其替换为className = {s.Ssome_class}
它不起作用。
这项工作
import React from 'react'
import s from './styles.module.css'
import { ReactComponent as Folder } from '../../assets/SVGs/folder.svg'
export default function Projects() {
return <Folder style={{ color: 'aqua', width: '42px' }} />
}
不起作用
import React from 'react'
import s from './styles.module.css'
import { ReactComponent as Folder } from '../../assets/SVGs/folder.svg'
export default function Projects() {
return <Folder className={s.some_class} />
}
我的styles.module.css
.some_class {
color: aqua;
width: 42px;
}
为什么className
不适合SVG组件?这里的方法是什么?
I'm now using inline style for the SVG react component, because if I replace it with className={s.some_class}
it does not work.
This works
import React from 'react'
import s from './styles.module.css'
import { ReactComponent as Folder } from '../../assets/SVGs/folder.svg'
export default function Projects() {
return <Folder style={{ color: 'aqua', width: '42px' }} />
}
This does not work
import React from 'react'
import s from './styles.module.css'
import { ReactComponent as Folder } from '../../assets/SVGs/folder.svg'
export default function Projects() {
return <Folder className={s.some_class} />
}
My styles.module.css
.some_class {
color: aqua;
width: 42px;
}
Why doesn't className
work for SVG component? and what's the approach here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论