Limit text length to n lines using CSS

后端 未结 13 1023
滥情空心
滥情空心 2020-11-22 02:53

Is it possible to limit a text length to \"n\" lines using CSS (or cut it when overflows vertically).

text-overflow: ellipsis; only works for 1 line tex

13条回答
  •  误落风尘
    2020-11-22 03:07

    I've been looking around for this, but then I realize, damn my website uses php!!! Why not use the trim function on the text input and play with the max length....

    Here is a possible solution too for those using php: http://ideone.com/PsTaI

     $max_length)
    {
       $offset = ($max_length - 3) - strlen($s);
       $s = substr($s, 0, strrpos($s, ' ', $offset)) . '...';
    }
    
    echo $s;
    ?>
    

提交回复
热议问题