Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 - Blending Mode between different HTML Elements

Tags:

html

css

blending

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>
like image 620
Murphy1976 Avatar asked Jun 09 '15 12:06

Murphy1976


People also ask

What are the various blend elements in CSS?

Approach: In CSS, there are two properties that allow us to blend color and/or image together: mix-blend-mode. background-blend-mode.

Which CSS property is used to set the 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.

Does CSS have blend modes?

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.


1 Answers

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>
like image 132
vals Avatar answered Sep 30 '22 12:09

vals