我有一個div背景圖像,我使用過濾器以黑白顯示(filter: grayscale(100%);
)。我現在試圖在該div內放置一個顏色圖標。試圖將圖標設置爲grayscale(0%)
,但這似乎不起作用。灰度(100%)容器內的彩色圖像
下面是一個例子:
#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(如果可能的話)。