我有一个 SVG,我想在某些事件中将它的颜色更改为红色,但是你不能用 SVG 作为背景图像来做到这一点,所以你必须使用 CSS image-mask
。我正在使用 PHP 将我的 CSS 回显到 div 的样式属性上:
$jfid = "background-color:red;
-webkit-mask-image:url(../like_icons/" . $iconfgg . ".svg);
mask-image:url(../like_icons/" . $iconfgg . ".svg)";
喜欢
.buttonlikee {
background: transparent;
outline: none;
border: none;
margin-left: 10px;
transition: 0.8s all ease
}
.ts{
width: 34px;
height: 32px;
background-color:red;
-webkit-mask-image:url(https://svgshare.com/i/CB7.svg);
mask-image:url(https://svgshare.com/i/CB7.svg)
}
<button class="buttonlikee">
<div class="ts"></div>
</button>
这按预期工作,但返回相同 SVG 的重复图像。所以解决方案是no-repeat
最后添加这样的:
$jfid = "background-color:red;
-webkit-mask-image:url(../like_icons/" . $iconfgg . ".svg) no-repeat;
mask-image:url(../like_icons/" . $iconfgg . ".svg) no-repeat";
作为回报,这给了我一个充满红色的 div,你看不到像这样的图标
.buttonlikee {
background: transparent;
outline: none;
border: none;
margin-left: 10px;
transition: 0.8s all ease
}
.ts{
width: 34px;
height: 32px;
background-color:red;
-webkit-mask-image:url(https://svgshare.com/i/CB7.svg) no-repeat;
mask-image:url(https://svgshare.com/i/CB7.svg) no-repeat
}
<button class="buttonlikee">
<div class="ts"></div>
</button>
这是一个错误吗?有什么解决办法?