How can I do text-overflow: ellipsis on two lines?

前端 未结 4 621
半阙折子戏
半阙折子戏 2020-12-10 07:04

I have a container where the text may expand to two lines and it\'s 40px in height, with an 18px font size. When I do:

text-overflow: ellipsis;
white-space:          


        
4条回答
  •  无人及你
    2020-12-10 07:26

    You can do it using -webkit-line-clamp. But a hack is needed. You need to set the height of the div such that it can accommodate only two lines.

    See this codepen https://codepen.io/VamsiKaja/pen/xYZVzY

    HTML file :

    Pellentesque habitant morbi tristique senectus et netus et

    CSS file :

    p {
        width:250px;  
        font-size:20px;
        margin:1em;
        height:50px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    

    }

提交回复
热议问题