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

后端 未结 5 662
攒了一身酷
攒了一身酷 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:25

    you can set the line height of a text and with it knows the exact height of each row and set desired height of your container, simply doing this:

    .container {
        line-height:25px;
        height:75px;
        overflow:hidden;
    }
    

    Now everything works rightly :)

提交回复
热议问题