html - 我如何在CSS中将一个容器与两个不同的容器混合

标签 html css mix-blend-mode

我有一个容器,我想对其应用 mix-blend-mode: difference 以与其父容器和父容器的父容器混合(等等)。当我应用混合模式时,容器仅与其父容器混合。我怎样才能达到我之前描述的结果。

代码结构是这样的:

.sec1 {
  position: absolute;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  background-color: black;
}
.sec2 {
  position: absolute;
  left: 0;
  top: 100vh;
  width: 100vw;
  height: 100vh;
  background-color: white;
}
.svg1 {
  position: fixed;
  ...
}
<section class="sec1">
  <section class="sec2">
    <svg class="svg1" ...>
      <text ... style="...;mix-blend-mode:difference;"></text>
    </svg>
  </section>
</section>

提前致谢。

最佳答案

这取决于您想要实现的目标,因为这不是很清楚。 我建议您阅读来自 Codrops 的此类教程

否则,当使用 mix-blend-mode 时,结果可能取决于颜色和其他因素,但您也可以堆叠到一个点,例如,您可以创建一个类并应用该混合模式。 检查下面的这个基本示例。

body {
  background: gray;
}

.blend {
  mix-blend-mode: exclusion;

  font: caption;
  padding: 2rem;
  box-sizing: border-box;
}

main {
  width: 100%;
  background-color: aqua;
}

aside {
  background-color: beige;
}

a {
  background-color: green;
  color: black;
}
<main class="blend"> 
<p>This is main container </p>

<aside class="blend"> 
This is the sidebar 
<a href="#" class="blend"> Link </a> 
</aside>

</main>

关于html - 我如何在CSS中将一个容器与两个不同的容器混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58861563/

相关文章:

javascript - UI-router 未路由到新模板

css - 更改位置网格

javascript - 如何使用 javascript 获得 mix-blend-mode 滚动效果?

jquery - 无法使用 jquery 更改背景图像

html - 如何超链接 CSS 制作的图像?

html - 如何使用 Bootstrap 横向设计一个无序列表的图像?

css - 变音符号比其他字母粗

javascript - WP 在主导航中添加额外的标题?

CSS mix 混合模式/仅白色或黑色

css - 在 Chrome 上混合混合模式转换错误