【发布时间】:2022-01-11 04:06:16
【问题描述】:
我有一个 SVG 图标列表,其中包含我用来显示如下所示的颜色
我希望能够在我的 web 应用程序的其他地方重复使用这些 SVG,但要更改图标的颜色,这样它就不会显示颜色,而是只显示某种颜色的阴影。 (蓝色)
有没有办法通过 CSS 将其更改为类似于灰度的蓝色? (我宁愿不上传单独的 SVG 来执行此操作)
我得到的最接近的是关注这个How change hue of image with different colors with css filter to hue of blue
但我不希望图标后面有方形背景。 (我只是想让 SVG 改变颜色)
.background {
padding: 16px;
background: rgb(199, 229, 242);
}
.donut {
width: 32px;
height: 32px;
position: relative;
}
.donut::before, .donut::after {
content: '';
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
.donut::before {
background-color: gray;
mix-blend-mode: color;
}
.donut::after {
mix-blend-mode: overlay;
background-color: blue;
}
<div class="background">
<div class="donut">
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<path d="M23.778 4.36A14 14 0 0016 2v5a9 9 0 11-9 9H2A14 14 0 1023.778 4.36z" fill="#E1BD16"/>
<path d="M6.1 6.1A14 14 0 002 16h5a9 9 0 019-9V2a14 14 0 00-9.9 4.1z" fill="#F85F4E"/>
</svg>
</div>
</div>
【问题讨论】: