After posting a previous question, I am still on the quest to determine the exact position of each line of text within an element.
While I was successful in identifying the css lineHeight
attribute (as mentioned in the previous response), I encountered an issue - the height of my element ended up being slightly larger than what I calculated using the cumulative height considering the number of lines and the lineHeight
.
To illustrate:
Imagine a <p>
element that measures 2010px in height without any padding, border, or margin. Despite the values for scrollHeight
, offsetHeight
, and clientHeight
all aligning, there are supposedly 89 lines in the browser. The lineHeight
from the computedStyle()
computes to be 22.
By dividing 2010 by 22, we would expect approximately 91.37 lines
The strategy of rounding down works well for smaller elements, but how can one tackle accurately determining the correct number of lines with larger elements?
I speculate that there might be some minute space between these text lines which I have overlooked. Is there a way to identify and quantify it? Could this discrepancy be influenced by different font types? Or is it something controlled by the browser itself? Any insights or resources on this matter would be greatly appreciated.
Thank you!!
Update:
Further investigation revealed that my <p>
has 26 superscripts, each extending upwards by 2px, adjusting the lineHeight
of those lines to 24px where they appear. This explains the missing space conundrum. (Exciting progress so far!)
Now, the challenge at hand is figuring out a method to dynamically calculate the additional upward extension of these superscripts above the standard line top, or understanding the baseline difference between a <sup>
and the regular baseline. Is there a CSS approach to address this complexity?