Search code examples
cssbackground-imagefill

Animate text fill from left to right


I wanted to animate a the text fill with CSS. The Text should be filled with color from left to right.

this is my CSS:

.box-with-text {
    background-image: -webkit-linear-gradient(right, crimson 50%, white 50%);
    background-repeat: repeat;
    background-position: 0 0;
    background-size: 200% 100%;
    -webkit-text-fill-color: transparent;
    -webkit-background-clip: text;
    -webkit-animation: stripes normal forwards ease-in-out;
    animation: stripes 2s normal forwards ease-in-out;
}

Now only the first letter is color-filled.

here is the fiddle


Solution

  • you may also take a look at flex (for centering things) and mix-blend-mode, so it can be avalaible also for Firefox:

    .box-with-text {
      text-transform: uppercase;
      font: bold 26vmax/.8 Open Sans, Impact;
      background: black;
      display: table;
      color: white;
      mix-blend-mode: multiply
    }
    
    @-webkit-keyframes stripes {
      to {
        background-size:100% 100%;
      }
    }
    
    @keyframes stripes {
      to {
        background-size:100% 100%;
      }
    }
    
    html {
      display: -webkit-box;
      display: -webkit-flex;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-align:center;
      -webkit-align-items:center;
          -ms-flex-align:center;
              align-items:center;
      height: 100%;
      background: black;
    }
    
    body {
      margin: auto;
      background: -webkit-linear-gradient( crimson , crimson) turquoise no-repeat 0 0;
      background: linear-gradient( crimson , crimson) turquoise no-repeat 0 0;
      background-size: 0 100%;
      -webkit-animation: stripes 2s linear infinite;
              animation: stripes 2s linear infinite;
    }
    <div class="box-with-text">
      Text
    </div>

    http://codepen.io/gc-nomade/pen/XKNKzd