How to set element height for a fixed number of lines of text

后端 未结 5 659
攒了一身酷
攒了一身酷 2021-02-05 02:54

Given some text that occupies about 10 rows, how can I resize its container to only show the first 3 rows and hide the others? Apparently this works, but I think it is not relia

5条回答
  •  醉梦人生
    2021-02-05 03:29

    You can use the webkit property line-clamp

    .container {
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;  
    }
    

    It doesn't work on all browsers, but hopefully it will one day.

提交回复
热议问题