Oze*_*ich 7 css button vertical-alignment
我有这个布局:

我的CSS:
body {
background: #e2eaed;
}
a {
text-decoration: none;
color: #fff;
font-size: 30px;
height: 62px;
line-height: 62px;
/* vertical-align: middle is not works */
background: #8dc73f;
width: 132px;
padding: 0 25px;
font-size: 16px;
text-align: center;
font-weight: bold;
margin-left: 4px;
display: block;
float: left;
}
Run Code Online (Sandbox Code Playgroud)
当按钮有1行文本时,我的代码运行良好.但是当按钮有2行文本时,如上图所示.代码文本有很高的高度,因为我使用了line-height属性.我试过了vertical-align但是没有用.
请看jsfiddle.
Pav*_*vlo 12
另一种方法是使用灵活的盒子:
a {
display: inline-flex;
align-items: center; /* cross axis */
justify-content: center; /* main axis */
line-height: 1; /* reset */
}
Run Code Online (Sandbox Code Playgroud)
垂直对齐仅影响显示为表格单元格的元素(或内联块,但后面的效果不同).这些元素不得浮动.
a {
display: table-cell;
vertical-align: middle;
/* Reset */
float: none;
line-height: normal;
}
Run Code Online (Sandbox Code Playgroud)