(This question was originally mentioned in w3c schools, I fixed this link)
According to w3c , the CSS value of line-height
can be set as follows:
<number>
property value used is a number times the font size of the element. Negative values are illegal. The calculated value matches the set value.
<percentage>
calculated property value is the percentage times the size of the calculated element size.
So line height = font-size × number
or line height = font-size × percentage ÷ 100%
, which should be the same.
And the line height is inherited.
However, I noticed that nested elements that increase the font size lead to completely different line heights, as can be seen here:
Column C (blue) is what I expected.
See jsfiddle .
Column A, if you forgive this mashup of css syntax for the sake of brevity:
div {line-height:140%;} > div > div «content»
Column B:
div {line-height:140%;} > div > div {line-height:140%} «content»
Column C:
div {line-height:140%;} > div > div {line-height:1.40} «content»
Half way understanding
Thus, it looks like column A, the line height is calculated as the length (for example, pixels) and set to the outer div font-size
. This computed length value is then inherited, so it looks compressed when the font size subsequently increases.
The specifications for both relate to the value multiplied by the font size. Thus, this refers to the font size of the element on which the line-height is set, and not the font size of the element that inherits the height of the line.
So, this halfway explains. But columns B, C differ by only 1.4 or 140%, which are the same. Sure?!
I would expect the behavior of blue column C, at least for columns B and C. (Although I think it's rather strange that this is not column A, but at least I understand that.)
I checked, and Firefox and Chromium do the same.
Can you explain?