How can I center icon and text inside of the button without specifiing the sizes to align items?
.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>
You can add vertical-align: middle
to the class ico
.
Fiddle at: https://jsfiddle.net/mnet4hn4/
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;
}
<button>
<span class=ico></span>
<span>And some text</span>
</button>
Works fine in Chrome, FF, IE (tested in 11), Opera 12
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With