Closed fuxter closed 12 years ago
This also happens when using unitless line-heights - which are better anyway ;)
This is an interesting problem. I'm working on a bug fix that involves wrapping the element in a div, setting the element's text to a thin character like "i", measuring the wrapper div's inner height, then unwrapping the element and resetting its text.
Because of the DOM manipulations it's not particularly fast, but this appears to be the most reliable way to measure the line height of the text block in pixels.
Thoughts? Other ideas?
As a quick fix I tried a simple regex on the calculated line-height, which detected non-px values as used them as a multiplier of the font size. It worked well enough for my simple use case, but I noticed it miscalculated the number of lines in IE (so I specified 8 lines but the text was truncated at 7).
@gilmoreorless that's a nice alternative. The decision tree for each line-height unit could get a little messy though: ems, pixels, points, and unitless. Not sure how well points can be converted into pixels.
I've committed the fix I had mentioned earlier, let me know if it works as well as your quick fix.
(Fixed in 1.2)
Thanks, I'll test it out. Like I said, my solution worked for my simple case, but that's mainly because I ignored points completely ;)
if the element has line-height in ems, ex. { line-height: 1.5em; } it's just gets emptied on $.trunk8'ing.