【发布时间】:2019-08-25 04:45:18
【问题描述】:
我有一个 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>
这是一个错误吗?有什么解决办法?
【问题讨论】:
标签: html css image image-masking