7

I have a textarea whose line-height is set to "normal". However, I can still get the actual pixel value in FireFox:

// firefox
>>> $("#post_body").css('line-height')
"19.1167px"

Whereas I cannot in Chrome:

// chrome
>>> $("#post_body").css('line-height')
"normal"

How can I get the actual pixel line height in Chrome?

Tom Lehman
  • 85,973
  • 71
  • 200
  • 272
  • You just want to get the default line-height? You haven't set it? – Purag Dec 01 '11 at 04:45
  • 1
    The answer you seek is [here](http://stackoverflow.com/a/18430767/1195891). I made a modified [jsFiddle](http://jsfiddle.net/arttronics/AZ6hJ/) for his answer: See the middle button `calculateLineHeight()` for Chrome use. Edit: Enable the browsers console to view results. – arttronics Jan 27 '14 at 07:36

2 Answers2

-3

you can try set css:

#post_body {line-height:1;}

Then Chrome output will be actual pixel.

lemon郑
  • 690
  • 5
  • 15
-6

The line-height value is a number. This number represents a multiplicative of the current node's font size. This is more complicated if the font of the current node is measured in em or ex units and is set from several layers of inheritance but is not explicitly stated at the current node. This is the worst case scenario. In this case you would have to inject a lowercase "m" character and measure its pixel width using the clientWidth property and then remove it.

austincheney
  • 1,097
  • 7
  • 8
  • 2
    The question applies when `line-height` is `normal` (which is a legal value for this CSS property). So this answer, which starts with "The line-height value is a number" is not applicable here. I strongly advice you to remove it. – philippe_b Feb 10 '17 at 10:50