How to restrict character limit by line or # of characters with css?

后端 未结 2 491
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-05 16:15

Is there a css property that can do one of the following? But first, let me explain.

Imagine a masonry layout where each item is width: 200px; and each would be height:

2条回答
  •  孤城傲影
    2021-02-05 16:42

    Not characters, but you can set a width of an element in pixels and use text-overflow property which should add "...".

    Also, you can limit number of lines by setting height of an element to, for instance, 30px and setting line-height CSS property to 15px and add overflow:hidden. That way you will have exact two lines of text.

    .twoLines{
       height:30px;
       line-height:15px;
       overflow:hidden;
    }
    

提交回复
热议问题