I have an good idea what the answer is going to be, but I just want to make absolutely sure.
I have two elements, div.glass
and div.sound
, both contain a background-image. Is it possible to set the blending mode to each div so that they interact with each other? For example:
div.glass,
div.sound {
width: 597px;
height: 154px;
position: absolute;
}
div.glass {
background: url(glass.png) 0 0 no-repeat;
z-index: 9;
top: 5px;
left: 5px;
}
div.sound {
background: url(soundwave.png) 0 0 no-repeat;
z-index: 10;
blend-mode: multiply;
top: 50px;
left: 300px;
}
div.container {
position: relative;
}
<div class="container">
<div class="glass"></div>
<div class="sound"></div>
</div>
Approach: In CSS, there are two properties that allow us to blend color and/or image together: mix-blend-mode. background-blend-mode.
The background-blend-mode CSS property sets how an element's background images should blend with each other and with the element's background color.
You can use most of the blend modes available in a design tool with CSS, using the mix-blend-mode or the background-blend-mode properties. The mix-blend-mode applies blending to a whole element and the background-blend-mode applies blending to the background of an element.
You have 2 ways to use blend-modes
When doing it in the same element, the property is background-blend-mode.
But, when doing it with 2 elements. it is mix-blend-mode
div.glass,
div.sound {
width: 597px;
height: 154px;
position: absolute;
}
div.glass {
background: url(http://placekitten.com/1200/900) 0 0 no-repeat;
z-index: 9;
top: 5px;
left: 5px;
}
div.sound {
background: url(http://placekitten.com/1000/750) 0 0 no-repeat;
z-index: 10;
mix-blend-mode: difference;
top: 50px;
left: 300px;
}
div.container {
position: relative;
}
<div class="container">
<div class="glass"></div>
<div class="sound"></div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With