Is it possible to fade-out the end of a text line in CSS?

前端 未结 2 1134
悲&欢浪女
悲&欢浪女 2021-01-01 01:32

I\'ve seen various examples of how to fade out a line of text in CSS. However, these all involve a gradient overlay which matches the background colour. Usually this might

相关标签:
2条回答
  • 2021-01-01 02:09

    Is something like this what you're looking for?

    div {
      background: linear-gradient(to bottom right, red, yellow);
    }
    h2 {
        background-image: linear-gradient(90deg,#000000 0%,rgba(0,0,0,0));
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        position:relative;
        display:inline-block;
        font-size: 50px;
    }
    <div>
      <h2>
        test test test test test
      </h2>
    </div>

    0 讨论(0)
  • 2021-01-01 02:21

    There is a sleek solution which uses mask-image. Yes, it uses a linear-gradient(), however, because it works with pure transparencies, no knowledge of the background color is necessary:

    div {
      white-space: nowrap;
      -webkit-mask-image: linear-gradient(to right, rgba(0,0,0,1) 90%, rgba(0,0,0,0));
    }
    

    Works for me in Chrome and caniuse for mask-image looks not bad.

    0 讨论(0)
提交回复
热议问题