如何以相同的方式垂直对齐标签和按钮内的图标
How to vertical align icon inside label and button in the same way
我正在尝试使 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;
}
请参阅fiddle:http://jsfiddle.net/zbhjco0j/
如何在这两种情况下使图标居中?
谢谢
添加 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;
}
我正在尝试使 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;
}
请参阅fiddle:http://jsfiddle.net/zbhjco0j/
如何在这两种情况下使图标居中?
谢谢
添加 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;
}