混合混合模式按钮悬停事件问题

时间:2017-01-20 07:57:35

标签: html css pseudo-element mix-blend-mode

我试图让mix-blend-mode工作,以便发生背景幻灯片。我把a jsfiddle of it sort of working放在了一起。

问题是,需要它看more like this

但我不想摆脱它上面的歪斜或从右边滑入。我尝试使用与该示例中相同的混合模式,但无论我做什么,它都不会在悬停时保持红色幻灯片颜色,在红色下保持白色文本。我想只使用伪元素,并将html保持在最低限度。我认为这可能是使用伪元素,但混合模式不与我合作,不知道如何让它看起来更像是第二小提琴。我的HTML如下:

<a href="#" class="btn">View Project</a>

CSS是:

a {
  position: relative;
  text-decoration: none;
  display: inline-block;
  padding: 15px 30px;
  border: 1px solid #f16251;
  background: black;
  color: #f16251;
  font-size: 30px;
  font-family: arial;
  mix-blend-mode: normal;
  overflow:hidden;
  z-index: 1;
}
a:before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: 100%; height: 100%;
  background: red;
  mix-blend-mode: multiply;
  transform-origin:0 0 ;
  transform:translateX(100%) skewX(30deg);
  transition: transform .25s;
  z-index: 3;
}
a:hover:before {
  transform: translateX(45%) skewX(30deg);
}
a:hover:after {
  position: absolute;
  top: 0; bottom: 0; left: 0; right: 0;
  width: 100%;
  height: 100%;
  background: white;

}
a:after {
    content: '';
    position: absolute;
    top: 0; bottom: 0; right: 0;
    width: 100%; height: 100%;
    background: white;
    mix-blend-mode: difference;
    z-index: 2;
}

只有当红色滑过该文字时,如何才能让背景文字显示为白色?我的mix-blend-mode代码必须是错的,但看起来可以在这里做。

1 个答案:

答案 0 :(得分:1)

嗯,这很有趣:)

&#13;
&#13;
a {
  position: relative;
  text-decoration: none;
  display: inline-block;
  padding: 15px 30px;
  border: 1px solid #f16251;
  background: white;
  color: black;
  font-size: 30px;
  font-family: arial;
  mix-blend-mode: normal;
  overflow:hidden;
  z-index: 1;
}

a:before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: 100%; height: 100%;
  background: white;
  mix-blend-mode: difference;
  transform-origin:0 0 ;
  transform:translateX(100%) skewX(30deg);
  transition: transform .25s;
  z-index: 3;
}
a:hover:before {
  transform: translateX(45%) skewX(30deg);
}

a:after{
  content: '';
  display:block;
  top: 0;
  left:0;
  bottom:0;
  right:0;
  position: absolute;
  z-index: 100;
  background: #f16251;
  mix-blend-mode: screen;
}
&#13;
<a href="#" class="btn">View Project</a>
&#13;
&#13;
&#13;