【发布时间】:2019-11-20 10:19:45
【问题描述】:
我一直在尝试在 React 中填充 SVG 组件的颜色,但它不起作用。
我尝试过使用图像标签来 React。但是,我在 React 文档中读到不支持带有 img 标签的 CSS。
//css
.dotSvg{
position: relative;
fill: #5AE2EB;
}
//React
//import
import { ReactComponent as Dot } from './dot.svg';
//code itself
<div className="home">
<Dot className="dotSvg"/>
<h3>Home</h3>
</div>
我希望能够使用填充和其他类型的 SVG 可修改属性。
更新:这是我的 css 文件代码设置。 .dotSvg 是 .container 类的一个项目。仍然需要帮助
.container{ display: grid;
text-align: center;
grid-template-columns: auto auto auto auto auto;
position: sticky;
top: 0;
}
.dotSvg{ cursor: pointer;
position: r
elative;
fill: #5AE2EB;
}
///svg file
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 2 2" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><circle cx="1" cy="1" r="1" style="fill-opacity:0;"/></svg>
解决了!我发现 svg 有一个 fill-opacity: 0;样式,所以我删除了它,或者你可以把它放到一个来解决这个问题。
【问题讨论】:
标签: javascript css reactjs svg