css - 仅使用 CSS,有没有办法将特定图像的颜色更改为黑底白字?
问题描述
我使用 CSS 来创建一些流行网站的深色主题版本。
我遇到的问题之一是这样的图像:
https://www.gstatic.com/images/icons/material/system/1x/reply_black_20dp.png
https://www.gstatic.com/images/icons/material/system/1x/more_vert_black_20dp.png
网站用于background-image
显示这些图像。
当我应用filter: invert(1)
到这些图像时,我在 Firefox 中得到一个白底白字的图像。
有没有办法,只使用 CSS,让这些图像显示为黑底白字?filter
如果你使用或其他技术对我来说并不重要。
解决方案
只需应用白色背景,然后进行过滤:
img {
background: #fff;
filter: invert(1);
}
<img src="https://i.stack.imgur.com/ZLpPT.png">
并有背景:
img {
background: #fff;
}
.box {
background:
url(https://i.stack.imgur.com/ZLpPT.png) 0 0/20px 20px no-repeat,
#fff;
width:100px;
height:100px;
filter: invert(1);
}
<div class="box"></div>
推荐阅读
- javascript - 避免使用 html 标签制作元素发送消息
- nagios - Nagios XI API 将更改为 Nagios 核心 API
- javascript - 单击该文件夹名称时如何显示特定文件夹中的所有内容?
- sapui5 - 如何为链接类型 QuickViewGroupElement 添加点击事件?
- traefik - Traefik 不会偶尔在 Docker Compose 上将容器添加到后端
- rust - 我如何向编译器解释 T 以返回相同类型的方式实现 Add ?
- php - 为什么这些错误来自 casperjs?
- c++ - 试图擦除向量 C++ 中的所有未定义节点
- shopify - 使用循环索引动态输出液体对象
- javascript - 即使在页面刷新时如何知道以前的 URL?