How to vertically align text with icon font?
In this scenario, since you are working with inline
-level elements, you could add vertical-align: middle
to the span
elements for vertical centering:
.nav-text {
vertical-align: middle;
}
Alternatively, you could set the display
of the parent element to flex
and set align-items
to center
for vertical centering:
.menu {
display: flex;
align-items: center;
}
There are already a few answers here but I found flexbox to be the cleanest and least "hacky" solution:
parent-element {
display: flex;
align-items: center;
}
To support Safari < 8, Firefox < 21 and Internet Explorer < 10 (Use this polyfill to support IE8+9) you'll need vendor prefixes:
parent-element {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}