.icon {
display: inline-block;
width: 2em;
height: 2em;
transition: .5s;
fill: currentColor;
stroke-width: 5;
}
.icon:hover {
fill: rgba(255,255,255,0);
stroke: black;
stroke-width: 2;
}
.red {
color: red;
}
.blue {
color: blue;
}
另一答案
如果您只是在真实颜色和黑白之间切换图像,可以将一个选择器设置为:
{滤波器:无;}
和另一个:
{filter:grayscale(100%);}
另一答案
知道这是一个老问题,但最近我们遇到了同样的问题,我们从服务器端解决了这个问题。这是一个特定于php的答案,但我很肯定其他envs有类似的东西。而不是使用img标签,你从一开始就将svg渲染为svg。
public static function print_svg($file){
$iconfile = new DOMDocument();
$iconfile->load($file);
$tag = $iconfile->saveHTML($iconfile->getElementsByTagName('svg')[0]);</