3

我有一些 html 文本,并想应用一些 css 对文本的像素执行以下操作:

  1. 使用下面的像素应用差异混合模式。
  2. 应用灰度滤镜
  3. 应用具有非常高设置的对比度过滤器。

这将允许将 UI 文本元素定位在图像上,同时仍然具有相当的可读性。

我做了不同的尝试,但仍然没有成功。这是我尝试将文本包装在容器中的一个。混合模式应用于实际的文本元素,而过滤器应用于包装器:

/* Filters and Blend Mode */

.h1Wrapper {
  filter: grayscale(1) contrast(200);
}

h1 {
  mix-blend-mode: difference;
  color: white;
}

/* SETUP */

.container {
  width: 600px;
  height: 200px;
  position: relative;
}

img {
  margin: auto;
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.h1Wrapper {
  position: absolute;
  top: 0px;
  width: 100%;
  height: 100%;
}

h1 {
  text-align: center;
  position: absolute;
  top: 0px;
  width: 100%;
}
<div class="container">

  <img src="https://upload.wikimedia.org/wikipedia/commons/f/f9/Phoenicopterus_ruber_in_S%C3%A3o_Paulo_Zoo.jpg">

  <div class="h1Wrapper">
    <h1>hello there, good morning, booboo sousa</h1>
  </div>

</div>

但是,如果您运行它,您会发现它不起作用。在这种情况下,混合模式似乎被忽略了。

When I tried to put the filter and blend mode css both on the h1 element, the filters where both applied before the blend mode, which lead to a different effect that I am trying to achieve.

For clarity, here is a photoshop version of the effect I am trying to achieve:

Photoshop version of the effect I am trying to achieve Layers of the Photoshop version

4

1 回答 1

3

I managed to solve this issue by stacking 3 layers of text over each other.

.container {
  text-align: center;
  position: relative;
  z-index: 100;
}

.split-text-wrap {
  position: relative;
  display: inline-block;
  margin: 0 auto;
}

.split-text {
  mix-blend-mode: color;
  color: #000;
}

.split-text1 {
  top: 0;
  position: absolute;
  mix-blend-mode: overlay;
  color: #fff;
}

.split-text2 {
  top: 0;
  position: absolute;
  color: #fff;
  opacity: .37;
}
<div class="container">
  <div class="split-text-wrap">
    <h2 class="split-text">
      Popuplar searches
    </h2>
    <h2 class="split-text1">
      Popuplar searches
    </h2>
    <h2 class="split-text2">
      Popuplar searches
    </h2>
  </div>
</div>

1st layer mixed using the colour 2nd layer made grey parts white 3rd layer changed blacks into greys

This was the result

I hope it's going to help.

于 2018-10-31T11:54:01.977 回答