How to apply a CSS gradient over a text, from a transparent to an opaque colour

前端 未结 2 1004
庸人自扰
庸人自扰 2020-12-02 10:52

Cheers!

I am a newbie in CSS/HTML, but I want to apply a gradient over a text, like that on the image below. How can I implement it with css?


 

2条回答
  •  执念已碎
    2020-12-02 11:18

    Try this example: http://jsbin.com/iwepas/3/ (tested on Firefox 18)

    The relevant CSS is on the pseudoelement :after of the

    wrapper I used

    article {
      position: relative;
    }
    
    article:after {
      position: absolute;
      bottom: 0;  
      height: 100%;
      width: 100%;
      content: "";
      background: linear-gradient(to top,
         rgba(255,255,255, 1) 20%, 
         rgba(255,255,255, 0) 80%
      );
      pointer-events: none; /* so the text is still selectable */
    }
    

    Output


    output


    Please note: on older browser you may need to use a from-transparent-to-opaque png background applied on the pseudoelement while other browser need vendor prefixes for linear-gradient

提交回复
热议问题