A
A
Abra Kadabra2015-11-16 01:02:26
css
Abra Kadabra, 2015-11-16 01:02:26

Is it possible to count the number of lines in a div?

Good evening.
The question is:
Is it possible to count the number of lines in a div ? Even if the characters are not separated in any way.
For example, like this word count. Everything is simple here.
The question is, can I do this with strings? (not separated by explicit hyphens)

ZY .
I think you can do something similar when dividing the height of the container by the height of the row.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexey Zuev, 2015-11-16
@Jmaster

In addition to dividing the height of the div by the height of the line, I can offer this solution .
The essence is simple - we insert a regular span into a div and count its number of regions through the getClientRects method

A
Azim Kurt, 2015-11-16
@Symphony

Number of rows = div height / 1 row height

N
Nazar Mokrinsky, 2015-11-16
@nazarpc

document.querySelector('div').textContent.split("\n").length

K
Konstantin Khairov, 2015-11-16
@Kaylos

Take two numbers 1st is the height of the "Height" property of this div block, and take the height of the text here's an example

.youdivblok{
height: 40px;
font-size: 10px;
}

It follows from this that there are exactly 4 lines in the div block

S
Stanislav Zadiraka, 2021-06-11
@algaucho

Take two numbers 1st is the height of the "Height" property of this div , and take the height of the text here's an example.
And lineheit won't break anything?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question