比如一个普通的按钮,要做到文字垂直居中
<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来控制高度等方法,都不行,都是偏上的,这个问题怎么解决啊?
Coincidentally, I encountered the same problem some time ago,
Solution: Use flex layout.
Set the parent element to:
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