So the actual height of an inline text element is not simply the font-size
value, but is determined by the individual font's metrics, as explained in this answer (see also this article).
So for the font I'm using, the ascent is 96.7%, the descent is 28.3%, resulting in a total content-area of 125%.
This means that for a base font size of 15px, the actual element's height should be 18.75px. The browser rounds that up to 19px. I can work with that.
Except, that when you zoom in or out, the height changes! This table shows the height in virtual CSS pixels, as reported by Chrome dev tools:
Zoom | Height |
---|---|
50% | 18px |
67% | 19.5px |
75% | 18.67px |
80% | 18.75px |
90% | 18.89px |
100% | 19px |
110% | 19.09px |
125% | 18.4px |
150% | 18.67px |
175% | 18.29px |
200% | 18.5px |
250% | 18.8px |
300% | 19px |
400% | 18.75% |
500% | 18.8px |
This is quite a wide range of values, and makes trying to align things difficult. I'm trying to apply padding to fill out the background-color to the full line-height as explained in this answer, which is not working reliably when the calculated element height changes but the padding value doesn't.
So to the question(s):
- How are these actual element height values calculated?
- Bonus question: is there any way to make it consistent across all zoom levels?