Text with two colors

后端 未结 6 1468
醉话见心
醉话见心 2021-01-11 11:49

I would like to have a text that switches its color at a certain point x. I have provided a sample that uses the text twice to produce the result, with the switch at 45px. I

6条回答
  •  悲&欢浪女
    2021-01-11 12:33

    Got it! Mixed a few things from the answers together to get this:

    div{
      border: 1px solid #000;
      position: relative;
      display: inline-block;
    }
    div>span{
      color: rgba(0, 0, 0, 0);
      z-index: 3;
    }
    
    div:before, div:after{
      content: attr(data-content);
      position: absolute;
      top: 0;
      left: 0;
      -webkit-touch-callout: none;
      -webkit-user-select: none;
      -khtml-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      user-select: none;
    }
    div:before{
      color: blue;
      clip: rect(0 200px 40px 45px);
      z-index: 1;
    }
    div:after{
      color: red;
      clip: rect(0 45px 40px 0);
      z-index: 2;
    }
    Some bicolored Text

    Upvoted all the answers for partial solutions.

提交回复
热议问题