【问题标题】:Why can't I apply css filters after mix-blend-mode?为什么我不能在混合混合模式后应用 css 过滤器?
【发布时间】:2019-03-25 06:16:36
【问题描述】:

我有一些 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>

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

当我尝试将过滤器和混合模式 css 都放在 h1 元素上时,过滤器都在混合模式之前应用,这导致了我想要实现的不同效果。

为清楚起见,这是我想要达到的效果的 Photoshop 版本:

【问题讨论】:

    标签: html css css-filters mix-blend-mode


    【解决方案1】:

    我设法通过堆叠 3 层文本来解决这个问题。

    .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>

    使用颜色混合的第一层 第二层灰色部分变成白色 第三层将黑色变为灰色

    This was the result

    我希望它会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-10
      • 2014-11-08
      • 2018-02-03
      • 1970-01-01
      • 2020-01-06
      • 1970-01-01
      • 2021-06-23
      相关资源
      最近更新 更多