文本填充颜色CSS

时间:2016-11-29 23:07:41

标签: html css

我一直在尝试使用CSS从左到右实现文本颜色填充,如下面的codepen.io/anon/pen/oYojzZ

但是,不是用颜色填充文本,而是填充背景。在此示例中,文本颜色黑色应该变为粉红色而不是背景。

非常感谢任何帮助。

由于

1 个答案:

答案 0 :(得分:0)



.tooltiptext {
    position: relative;
}
.popUpWord {
    color: pink;
}
.popUpWordBlack {
    color: black;
}
.outPop {
    margin: auto;
    background: none;
    width: 0;
    overflow: hidden;
    display: block;
    position: absolute;
    /* Unset our animation play state initially - this will reset the animation when the hover is no longer */
    animation-play-state: unset;
}
/* Since .outPop is hidden we add the style to either when the element is hovered or it's sibling is hovered */
.outPopBlack:hover + .outPop,
.outPop:hover{
    /* Turn our animation on when we are hovering over our element */
    animation: stripes 2s linear 1 forwards;
}
.outPopBlack {
    display: block;
    position: absolute;
    z-index: -1;
}
@keyframes stripes {
    to {
        width: 32px;
    }
}

<span class="tooltiptext"> 
  <span class="outPopBlack">
    <span class="popUpWordBlack">hello</span>
  </span>  
  <span class="outPop">
    <span class="popUpWord">hello</span>
  </span>  
</span>
&#13;
&#13;
&#13;