html - 如何使用 CSS 中的过滤器属性使颜色变为白色

标签 html css css-filters

我有一个 svg 图像,我想使用 css filter 属性更改 svg 的颜色。

body {
  background-color: #dadada;
}

.custom-1 {
  filter: invert(0.5);
}
<img src="https://image.flaticon.com/icons/svg/62/62945.svg" class="standard" width="50" height="50" alt="img">

<img src="https://image.flaticon.com/icons/svg/62/62945.svg" class="custom-1" width="50" height="50" alt="img">

如何将 svg 图像设为白色。

最佳答案

您可以像这样组合过滤器属性。

brightness(0) invert(1);

body {
  background-color: #dadada;
}

.custom-1 {
  filter: invert(0.5);
}

.custom-2 {
  filter:  brightness(0) invert(1);
}
<img src="https://s.cdpn.io/3/kiwi.svg" class="standard" width="50" height="50" alt="img">

<img src="https://s.cdpn.io/3/kiwi.svg" class="custom-1" width="50" height="50" alt="img">

<img src="https://s.cdpn.io/3/kiwi.svg" class="custom-2" width="50" height="50" alt="img">

编辑 - 2021 年 5 月 25 日:

这个答案非常受欢迎,因此我想提醒您,filter 不被 Internet Explorer and Opera Mini 支持 .好消息是Microsoft is slowly phasing out IE .

保重!

关于html - 如何使用 CSS 中的过滤器属性使颜色变为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52829623/

相关文章:

css - 预渲染 CSS 过滤器过渡?

javascript - 调整屏幕大小后子菜单不显示

python - 如何处理此错误 : __init__() got an unexpected keyword argument 'book_category'

css - 具有可互换 div 的 3 列布局

html - 具有柔性显示的并排画廊

javascript - 如何根据媒体查询调用js文件

css - 硬件加速时在 Chrome 中剪辑时不正确的 CSS 模糊渲染

javascript - 在 &lt;script&gt; 标记中附加到 URL 末尾时调整宽度和高度

asp.net - 我怎样才能在 html 字符串中找到额外的关闭 div

css - 带有 CSS3 模糊滤镜的 Div 在过渡时显示模糊边缘