Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is an element’s line-height (in pixels) affected by its parent’s font-size?

Tags:

css

See this example:

http://codepen.io/tomsoderlund/pen/JYJpPR

Try dragging the slider, which affects the font-size on the canvas element. But why does the line-height on the green boxes change? The line height is set in pixels.

like image 396
Tom Söderlund Avatar asked Nov 30 '25 06:11

Tom Söderlund


1 Answers

The <span>s are inline elements. Those are not affected by line-height as you wish.

replace the <span>s with <div>s or set CSS to display: block

On block level elements, the line-height property specifies the minimum height of line boxes within the element.

On non-replaced inline elements, line-height specifies the height that is used to calculate line box height. On replaced inline elements such as buttons or other input element, line-height has no effect.

https://developer.mozilla.org/en-US/docs/Web/CSS/line-height

like image 135
yunzen Avatar answered Dec 02 '25 19:12

yunzen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!