Fading out text on overflow with css if the text is bigger than allowed

前端 未结 8 1860
栀梦
栀梦 2020-12-22 23:13

I am trying to create a text fade-out effect when the amount of text is bigger than the row can handle. I am achieving this with the mixture of max-height,

8条回答
  •  离开以前
    2020-12-22 23:58

    Looks like your requirement is just to fade out the text beginning at a certain height (about 150px), the text (if any) presenting at that height is considered as overflow. So you can try using some kind of transparent linear gradient layer placed on top of the text area, we can achieve this in a neat way using the pseudo-element :before like this:

    .row:before {
      content:'';
      width:100%;
      height:100%;    
      position:absolute;
      left:0;
      top:0;
      background:linear-gradient(transparent 150px, white);
    }
    

    Fiddle

提交回复
热议问题