【发布时间】:2016-07-02 21:33:06
【问题描述】:
我有一个带有背景图像的 div,我正在使用过滤器将其显示为黑白 (filter: grayscale(100%);)。我现在正试图在该 div 中放置一个颜色图标。尝试将图标设置为grayscale(0%),但这似乎不起作用。
这是一个例子:
#a1, #a2 {
background-image: url(http://ndrichardson.com/blog/wp-content/uploads/2012/04/colorpsychology.jpg);
background-repeat: no-repeat;
background-size: 100% 100%;
}
#a1 {
height: 250px;
width: 250px;
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
position: relative;
}
#a2 {
height: 50px;
width: 50px;
-webkit-filter: grayscale(0%);
filter: grayscale(0%);
position: absolute;
top: 0px;
right: 0px;
}
<div id="a1"><!-- << this should be black and white -->
<div id="a2"><!-- << this should be color -->
</div>
</div>
有没有办法在不创建额外的 div 来保存背景图像的情况下做到这一点?真正的代码要复杂得多,这就是为什么我想尽可能避免使用额外的 div。
【问题讨论】:
标签: html css css-filters