Number of lines with javascript

I need to trim dynamic text to cut 2 lines from it (teaser). The problem is that the number of lines that accept the displayed line in a div depends on the characters used (for example, "w" and "i" do not have the same width), browser and OS (the font on the Mac is not exactly the same font on Windows).

Is there a way in javascript to trim text that will be longer than the x lines in the div (knowing that the length of the div is fixed)?

Thanks.

+4
source share
1 answer

you can use something like http://jsfiddle.net/cSTzn/ with overflow: hidden; and height

EDIT: an update was made with a link in the lower right corner, if necessary, configure http://jsfiddle.net/cSTzn/1/

+4
source

Source: https://habr.com/ru/post/1414484/


All Articles