css - 如何解决安卓上按钮文字偏上的问题
怪我咯
怪我咯 2017-04-17 11:48:07
0
5
587

比如一个普通的按钮,要做到文字垂直居中

<a>按钮</a>

css设置为:

a {
    height: 30px;
    line-height: 30px;
    font-size: 14px;
    text-align: center;
    width: 70px;
    vertical-align: middle;
}

在chrome上和ios上没有问题,但是在安卓上文字就会明显偏上,如图

试过用table-cell或者line-height设为1,然后用padding来控制高度等方法,都不行,都是偏上的,这个问题怎么解决啊?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(5)
迷茫

Coincidentally, I encountered the same problem some time ago,

Solution: Use flex layout.

Set the parent element to:

display: flex;
align-items: center;
justify-content: center;

There are no compatibility issues after using autoprefixer to add prefixes.

刘奇

The a element is an inline element and must be set as a block-level element. The set height line-height will take effect

迷茫

Adjust f12 to overwrite some of Android’s default styles

小葫芦

Well, anyway, I set line-height to be the same as height, so it will be centered up and down. However, it seems that your a can also be replaced by a button. The text in the button will automatically be centered up, down, left, and right

迷茫

This problem only occurs in special browsers. It is caused by line-height. Use flex layout instead

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template