使用CSS混合2个元素背景颜色

ksb*_*ksb 12 html javascript css photoshop css3

我需要使用CSS混合使用CSS的2个元素的背景颜色,background-blend-mode:multiply但是只有当我在同一个元素中有2种颜色时才能使用.

我需要实现这样的目标 -


在此输入图像描述

我一直在寻找,但一直无法弄清楚.我找到的最有用的资源是CSS中的新混合功能,它展示了如何使用Canvas进行操作.是否可以使用CSS做同样的事情?

编辑


上面的圆圈只是展示我需要的一个例子.正如我所提到的,我正在寻找两种不同元素的混合颜色.我为我的实际形状创造了一个小提琴,我需要混合. http://jsfiddle.net/fmgfsr4o/2/

pom*_*meh 1

您可以将 CSS 多重背景与径向渐变相结合来实现此效果:

CSS

div {
  /* adjust the width of the container to adjust circle's
     overlap size and shape */
  width: 80px;
  height: 50px;
  /* for debug purpose only */
  border: solid blue 1px;

  background:
    /* draw the red circle */
    radial-gradient(red 0%, red 70%, transparent 70%, transparent 100%) 0 0,
    /* draw the green circle */
    radial-gradient(green 0%, green 70%, transparent 70%, transparent 100%) 0 0;
    /* the red on the left, the green on the right */
  background-position: top left, top right;

  /* you can make then bigger or smaller */
  /* but you have to change width size above too */
  background-size: 50px 50px;
  /* You want both circles to appears once only */
  background-repeat: no-repeat;

  /* you can try with other values too */
  /* https://developer.mozilla.org/en-US/docs/Web/CSS/background-blend-mode */
  background-blend-mode: multiply;
}
Run Code Online (Sandbox Code Playgroud)

超文本标记语言

<div></div>
Run Code Online (Sandbox Code Playgroud)

我做了一个 JSFiddle 供你尝试:http://jsfiddle.net/pomeh/07nLpwwj/

这是我使用 Firefox 31 得到的结果:

界

即使浏览器支持看起来“正确”(请参阅​​此处http://caniuse.com/#feat=css-backgroundblendmode),请注意该background-blend-mode属性目前处于候选推荐状态,因此使用时要小心(感谢@Paulie_D 指出了这一点)。