Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does "vertical-align: middle" push text below surrounding text?

Eg.

1234<span style="vertical-align: middle">567</span>890

Will render with 567 slightly below the surrounding numbers.

http://jsfiddle.net/zBy9D/

like image 626
Jesse Avatar asked Feb 15 '23 02:02

Jesse


2 Answers

As mentioned by others, elements have a vertical-align of baseline by default.

In regards to why middle is lower than baseline, MDN says the following:

middle

Aligns the middle of the element with the middle of lowercase letters in the parent.

Since the height of the font text is greater than that of lowercase letters, the text becomes slightly lower.

like image 103
Zhihao Avatar answered Apr 09 '23 15:04

Zhihao


It's because text has, by default, vertical-align: baseline. Middle's slightly lower than baseline.

like image 42
knrz Avatar answered Apr 09 '23 13:04

knrz