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

前端 未结 8 1809
栀梦
栀梦 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:15

    I think your are looking for something like this, right?

    http://jsfiddle.net/QPFkH/

    .text {
        position:relative;
        width:200px;
        max-height:10em;
        overflow:hidden;
    }
    .shadow {
        position:absolute;
        top:8em;
        width:100%;
        height:2em;
        background: -webkit-linear-gradient(transparent, white);
        background: -o-linear-gradient(transparent, white);
        background: -moz-linear-gradient(transparent, white);
        background: linear-gradient(transparent, white);
    }
    
    0 讨论(0)
  • 2020-12-23 00:18

    If you don't need to rely on percentage values, use box-shadow instead of background-image. It makes it possible to let the user interact with the elements behind your fading-thingy, without the need of pointer-events: none (http://caniuse.com/#feat=pointer-events):

    box-shadow: 0 0 2em 1em #f00;
    height: 0;
    

    But be warned, box-shadow can slow down scrolling:

    • http://nerds.airbnb.com/box-shadows-are-expensive-to-paint
    0 讨论(0)
提交回复
热议问题