我想使用混合-混合-模式来更改移动背景SVG上的文本 colored颜色 .

我的问题是,我找不到正确的 colored颜色 . 我想要黄色背景上的红色文本和红色背景上的黄色文本,但我得到的是绿色文本. Image of the problem

我试了很多方法,拿到了一支钢笔,你可以看到问题所在.

这是我的钢笔: https://codepen.io/nicopoggenburg/pen/xxmjmNQ

    <div class="box">
      <div class="svgs">
        <div class="svg-container">
          <svg class="svg svg-1" viewBox="0 0 1024 244" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M1029 59.77c-258.25 0-258.25 124.62-516.5 124.62S254.25 59.77-4 59.77" stroke="red" stroke-width="118.634" stroke-miterlimit="10"/>
      </svg>
        </div><div class="svg-container">
          <svg class="svg svg-2" viewBox="0 0 1024 244" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M1029 59.77c-258.25 0-258.25 124.62-516.5 124.62S254.25 59.77-4 59.77" stroke="red" stroke-width="118.634" stroke-miterlimit="10"/>
      </svg>
        </div>
      </div>
      <h1 class="text">Do reinvent<br>the wheel</h1>

    </div>
    @keyframes moveWave {
      0% {
        transform: translateX(0);
      }
      100% {
        transform: translateX(-50%);
      }
    }

    :root {
      --light: yellow;
      --dark: red;
    }
    .box {
      position: relative;
      overflow: hidden;
      background: var(--light);
      color: var(--light);
      padding: 20px 0;
    }
    .svgs {
      display: flex;
      width: 200%;
      animation: moveWave 5s linear infinite;
      height: 100%;
      display: flex;
      align-items: center;
    }
    .svg-container {
      width: 100%;
    }
    .svg {
      width: 100%;
      height: auto;
    }
    .svg-1 {
    }
    .svg-2 {
    }
    .text {
      position: absolute;
      top: 50%;
      left: 50%;
      width: 80%;
      transform: translate(-50%, -50%);
      text-align: center;
      font-size: 90px;
      text-transform: uppercase;
      margin: 0;
      mix-blend-mode: difference;
      font-weight: 800;
    }

有没有人有好的解决方案?

我感谢每一个提示!

推荐答案

需要再次显示具有第二种 colored颜色 的文本(例如,使用.text:after)并应用mix-blend-mode: difference;:

@keyframes moveWave {
  to {
    transform: translateX(-50%);
  }
}

:root {
  --light: yellow;
  --dark: red;
}
.box {
  position: relative;
  overflow: hidden;
  background: var(--light);
  color: var(--light);
  padding: 20px 0;
}
.svgs {
  display: flex;
  width: 200%;
  animation: moveWave 5s linear infinite;
  display: flex;
  align-items: center;
}
.svg-container {
  width: 100%;
}
.svg {
  width: 100%;
}
.text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-size: 90px;
  text-transform: uppercase;
  margin: 0;
  mix-blend-mode: difference;
  font-weight: 800;
  width: fit-content;
  color: var(--dark);
}

.text:after {
  content: attr(data-text);
  mix-blend-mode: difference;
  position: absolute;
  left: 0;
  top: 0;
  color: var(--light);
}
<div class="box">
  <div class="svgs">
    <div class="svg-container">
      <svg class="svg svg-1" viewBox="0 0 1024 244" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M1029 59.77c-258.25 0-258.25 124.62-516.5 124.62S254.25 59.77-4 59.77" stroke="red" stroke-width="118.634" stroke-miterlimit="10"/>
      </svg>
    </div>
    <div class="svg-container">
      <svg class="svg svg-2" viewBox="0 0 1024 244" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M1029 59.77c-258.25 0-258.25 124.62-516.5 124.62S254.25 59.77-4 59.77" stroke="red" stroke-width="118.634" stroke-miterlimit="10"/>
      </svg>
    </div>
  </div>
  <h1 class="text" data-text="Do reinvent the wheel">Do reinvent<br>the wheel</h1>
</div>

Css相关问答推荐

悬停时可展开的按钮与屏幕右侧对齐,如何保持未悬停的按钮正确对齐?

使用高图的背景大小渐变

如何更改Swiper Navegation默认 colored颜色

如何通过重复的网格区域来简化网格布局?

为什么 width: 100% 在 Flex 父级中缩小这个 div ?

Bootstrap 和 Sass:将 SCSS 文件转换为 CSS 时出错.错误:$theme-colors-rgb 中未定义变量 @each $color、$value

解释 "document.styleSheets[0].cssRules[0].style;"

如何在一个父类里面 Select 两个不同的类?

使用带有 fr 单位的 calc 函数

Bootstrap 5 - 更改列顺序时出现问题

如何让我的 CSS 代码响应小屏幕?

如何使用 TailwindCSS 水平设置输入和按钮

使用 styled-components,我如何定位组件的子类?

CSS如何防止键盘向上移动内容?

您如何设置 Google Places Autocomplete API 的下拉菜单样式?

水平列表项

如何动态生成用逗号分隔的类列表?

删除所有填充和边距表格 HTML 和 CSS

使用 CSS 垂直居中旋转文本

如果容器 div 较小,如何将子 div 扩展到 100% 屏幕宽度?