Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply mix-blend-mode while keeping text opaque?

I need some help recreating this in CSS (if possible) :

this

And here is what I have so far:

.bg {
  background-image: url('https://images.unsplash.com/photo-1501706362039-c06b2d715385?auto=format&fit=crop&w=1070&q=60&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D');
  background-repeat: no-repeat;
  background-position: center center;
  padding: 100px 50px;
}

.text {
  background: #ed1c24;
  mix-blend-mode: multiply;
}

.text p {
  font-family: "Helvetica";
  font-weight: bold;
  font-size: 32px;
  color: #fff;
  margin: 0;
  padding: 40px;
}
<div class="bg">
  <div class="text">
    <p>
      These artistic movements were a refelection of the million of people who lived and worked here. To them, "I ❤ NY" could be read as a rallying cry.
    </p>
  </div>
</div>

There is a div with a background image and overlaying that div is another one with a red bg color and mix-blend-mode: multiply on it. It looks like the color blend is working correctly, but is there a way that I can make the white text be unaffected and an opaque solid white like in the example image?

like image 663
mc5 Avatar asked Nov 15 '17 20:11

mc5


People also ask

What does mix blend-mode screen do?

The mix-blend-mode CSS property sets how an element's content should blend with the content of the element's parent and the element's background.

Why does mix blend-mode not work?

The reason why it doesn't work is that the white sections don't really have a white background. They have no background-color set, so they fall back to the default value of transparent . Visually this is manifested as a white color, but to the compositor it will still be transparent .

What is mix blend-mode difference?

The mix-blend-mode applies blending to a whole element and the background-blend-mode applies blending to the background of an element. You use background-blend-mode when you have multiple backgrounds on an element and want them all to blend into each other.

What does exclusion blending mode do?

Exclusion. Exclusion is very similar to Difference. Blending with white inverts the base color values, while blending with black produces no change. However, Blending with 50% gray produces 50% gray.


1 Answers

You may use pseudo element and apply mix-blend-mode: multiply on it like this :

.bg {
  background-image: url('https://images.unsplash.com/photo-1501706362039-c06b2d715385?auto=format&fit=crop&w=1070&q=60&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D');
  background-repeat: no-repeat;
  background-position: center center;
  padding: 100px 50px;
}

.text {
  position: relative;
}

.text:before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  background: #ed1c24;
  mix-blend-mode: multiply;
  z-index: 0;
}

.text p {
  font-family: "Helvetica";
  font-weight: bold;
  font-size: 32px;
  color: #fff;
  margin: 0;
  padding: 40px;
  z-index: 2;
  position: relative;
}
<div class="bg">
  <div class="text">
    <p>
      These artistic movements were a refelection of the million of people who lived and worked here. To them, "I ❤ NY" could be read as a rallying cry.
    </p>
  </div>
</div>
like image 62
Temani Afif Avatar answered Sep 22 '22 12:09

Temani Afif