cssgradientbackground-blend-mode

CSS Background-Blend-Mode over two Elements


Lets assume I have a div with a Gradient applied as a background-property. I now want to overlay a black PNG (of smaller size) and set the PNG to have a background-blend-mode of overlay. Unfortunately I have no idea on how to achieve this.

I know I can have a working background-blend-mode when I render the Gradient into the CSS of the Div with the PNG image like:

background: url(../img/plus.png), linear-gradient(to bottom, #24cae4 0%, #1f81e3 100%);
background-blend-mode: overlay;

This however results in the Gradient being as small as the actual PNG, which is not a desired effect, like this: enter image description here

What I want to achieve is this with pure CSS (if possible):

Overlay PNG on top of a div with CSS-rendered Gradient

Here a Codepen to illustrate what I'm trying to do: http://codepen.io/anon/pen/zxOXGP Notice the Black Icon. I wanna overlay this.


Solution

  • Try using mix-blend-mode instead of background-blend-mode and switch to simple text for the plus-sign or a webfont for more custom figures.

    Example Codepen of the below:

    .placeholder {
      position: relative;
      width: 400px;
      height: 300px;
      background-image: -moz-linear-gradient(#ff0000, #0000ff);
      background-image: -webkit-linear-gradient(#ff0000, #0000ff);
      background-image: linear-gradient(#ff0000, #0000ff);
    }
    .center {
      position: absolute;
      top: 25%;
      width: 100%;
      font-size: 120px;
    }
    .center span {
      display: block;
      text-align: center;
      color: red;
      mix-blend-mode: screen;
    }
    <div class="placeholder">
      <div class="center"><span>+</span>
      </div>
    </div>