Why does “vertical-align: middle” push text below

2019-07-06 20:26发布

Eg.

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

Will render with 567 slightly below the surrounding numbers.

http://jsfiddle.net/zBy9D/

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-07-06 20:30

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

查看更多
\"骚年 ilove
3楼-- · 2019-07-06 20:41

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.

查看更多
登录 后发表回答