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

前端 未结 8 1894
栀梦
栀梦 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-23 00:03

    I’d suggest something like this:

    Apply the gradient to an absolutely positioned pseudo-element (:after), that get’s positioned at say 160px from top with 40px height – that way, it’ll not be shown at all in shorter boxes (because of their max-height in combination with overflow:hidden). And the gradient itself is from totally transparent (rgba(0,0,0,0)) to solid black.

    .row{
        position:relative;
        /* … */
    }
    .row:after {
        content:"";
        position:absolute;
        top:160px;
        left:0;
        height:40px;
        width:100%;
        background: linear-gradient(rgba(0,0,0,0), #000);
    }
    

    http://jsfiddle.net/b9vtW/2/

提交回复
热议问题