我正试图在ul / li标签内垂直居中一个图标。 如果将图标放在按钮标签和标签标签内,我会得到两个不同的结果,我无法在标签中找到对齐方式。
<ul>
<li><label class="btn"><i class="fa fa-anchor"></i></label></li>
<li><button class="btn"><i class="fa fa-anchor"></i></button></li>
<li><button class="btn"><i class="fa fa-anchor"></i></button></li>
</ul>
的CSS:
li{
display: inline-block;
text-align: center;
vertical-align: middle;
box-sizing: border-box;
margin: 0;
border: 1px solid;
}
button,
label{
position: relative;
cursor: pointer;
padding: 0;
margin: 0;
background: transparent;
color: inherit;
font-size: 16px;
border: none;
outline: none;
width: 41px;
height: 41px;
padding: 0 5px;
margin: 0 2px;
text-align: center;
display: inline-block;
box-sizing: border-box;
}
button:hover,
label:hover{
background-color: #4E84BB;
color: white;
}
请看小提琴:http://jsfiddle.net/zbhjco0j/
如何在两个场景中居中显示图标?
感谢
答案 0 :(得分:0)
将line-height: 41px;
添加到button, label
Demo
CSS:
button,
label{
position: relative;
cursor: pointer;
padding: 0;
margin: 0;
background: transparent;
color: inherit;
font-size: 16px;
border: none;
outline: none;
width: 41px;
height: 41px;
line-height: 41px; /* newly added */
padding: 0 5px;
margin: 0 2px;
text-align: center;
display: inline-block;
box-sizing: border-box;
}