如何将按钮内的图标和文字居中,而不指定尺寸以对齐项目?
.ico {
background: url(https://www.gravatar.com/avatar/cbfaff96665b7567defe1b34a883db8b?s=32&d=identicon&r=PG);
width: 32px;
height: 32px;
display: inline-block;
}

<button>
<span class=ico></span>
And some text
</button>
&#13;
答案 0 :(得分:1)
https://jsfiddle.net/nog2kuta/
.ico {
background: url(//www.gravatar.com/avatar/cbfaff96665b7567defe1b34a883db8b?s=32&d=identicon&r=PG);
width: 32px;
height: 32px;
display: inline-block;
}
button {
padding: 3px;
}
button span {
display: inline-block;
vertical-align: middle;
}
&#13;
<button>
<span class=ico></span>
<span>And some text</span>
</button>
&#13;
在Chrome,FF,IE(11中测试),Opera 12
中运行良好答案 1 :(得分:1)
您可以将vertical-align: middle
添加到课程ico
。
小提琴:https://jsfiddle.net/mnet4hn4/