1

Here is my current HTML:

.titleText {
  font-family: Hacked;
  font-size: 8rem;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  text-align: center;
}

.titleContainer {
  position: relative;
}

body {
  margin: 0;
}
<!DOCTYPE html>
<div class="titleContainer">
  <img src="assets/ethan.png">
  <h1 class="titleText">Ethan Brand</h1>
</div>

I want the text over the image to be the "opposite of transparent", inversing the color behind each pixel of text. I found this: How can I invert color using CSS? but that changes all of the text, not taking the inverse of each pixel.

Thanks!

Ori Drori
  • 183,571
  • 29
  • 224
  • 209
Jack Crane
  • 61
  • 5

1 Answers1

0

Use mix-blend-mode: difference; with color: white on the text:

.titleText {
  font-family: Hacked;
  font-size: 8rem;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  text-align: center;
  mix-blend-mode: difference;
  color: white;
  margin: 0;
}

.titleContainer {
  position: relative;
}

body {
  margin: 0;
}
<div class="titleContainer">
  <img src="https://picsum.photos/800/400">
  <h1 class="titleText">Ethan Brand</h1>
</div>
Ori Drori
  • 183,571
  • 29
  • 224
  • 209
  • 1
    Just for the sake of a fuller answer here is a link to documentation of `mix-blend-mode` on MDN https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode – Ivar Oct 09 '19 at 16:55