How to vertically align text across browsers

白昼怎懂夜的黑 提交于 2019-12-05 21:07:37

Two properties in your css

 display: table-cell;
    vertical-align: middle;

Check to live demo http://jsfiddle.net/UQ4D5/5/

Learn to use reset.css or normalize.css for prevent small differences in browser rendering models.

And then use height=line-height trick:

div {
    font-size: 100px;
    text-align: center;
    height: 120px;
    line-height: 120px;
    border: 1px solid black;
}

chrome metrics:


firefox metrics:

Height is the same in both cases.

The issue is based on the Browser default Stylesheets. I recommend you to use a proper reset Stylesheet or even normalize.css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!