我正在尝试创建类似于这支笔上显示的双色调效果:https ://codepen.io/meowwwls/pen/zoRjdK
我的尝试在这里,并且完全按照我想要的方式工作,用于普通的 img 标签:https ://codepen.io/sunnywz/pen/zPyYYR
$dark_blue: #080c29;
$white_blue: #dbe6ec;
.duotone {
display: inline-block;
position: relative;
vertical-align: top;
width: auto;
&:before,
&:after {
content: "";
opacity: 1;
pointer-events: none;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
transition: 0.5s;
-webkit-transition: 0.5s;
}
&:before {
background: $dark_blue;
mix-blend-mode: color;
z-index: 1;
}
&:after {
background: $white_blue;
mix-blend-mode: color;
z-index: 2;
}
img {
filter: grayscale(1) contrast(1) brightness(1);
-webkit-filter: grayscale(1) contrast(1) brightness(1);
vertical-align: middle;
}
&:hover {
&:before,
&:after {
opacity: 0;
transition: 0.5s;
-webkit-transition: 0.5s;
}
img {
filter: none;
-webkit-filter: none;
}
}
}
.duotone-background {
background-size: cover;
display: inline-block;
filter: grayscale(1) contrast(1) brightness(1);
-webkit-filter: grayscale(1) contrast(1) brightness(1);
height: 386px;
position: relative;
width: 640px;
vertical-align: top;
&:before,
&:after {
content: "";
opacity: 1;
pointer-events: none;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
transition: 0.5s;
-webkit-transition: 0.5s;
}
&:before {
background: $dark_blue;
mix-blend-mode: color;
z-index: 1;
}
&:after {
background: $white_blue;
mix-blend-mode: color;
z-index: 2;
}
&:hover {
filter: none;
-webkit-filter: none;
&:before,
&:after {
opacity: 0;
transition: 0.5s;
-webkit-transition: 0.5s;
}
}
}
但是当我将相同的样式和伪元素应用于具有背景图像的 div 时,它会产生完全不同的效果,正如您在第二张图像中看到的那样。
我试图在带有背景混合模式的 div 上使用 $dark_blue 颜色,但这似乎根本不起作用。
如何在背景图像上达到相同的效果?