A191919 A191919 - 6 months ago 14
HTML Question

Fontawasome vertical icon align

Why

vertical-align: middle;
does not align icons to middle of a header?



.custom {
color: white;
vertical-align: middle;
}
.header {
width: 100%;
height: 40px;
background: rgb(40,40,40);
}

<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"/>
<div class="header">
<i class="fa fa-facebook custom" aria-hidden="true"></i>
<i class="fa fa-twitter custom" aria-hidden="true"></i>
<i class="fa fa-instagram custom" aria-hidden="true"></i>
<i class="fa fa-google-plus custom" aria-hidden="true"></i>
</div>




Answer

these days, the best way to align to center vertically is to use flexbox. See also:

https://css-tricks.com/snippets/css/a-guide-to-flexbox/

https://philipwalton.github.io/solved-by-flexbox/demos/vertical-centering/

.custom {
        color: white;
        vertical-align: middle;
    }

.header {
  
  display:flex;
  align-items: center;

        width: 100%;
        height: 40px;
        background: rgb(40,40,40);
    }
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"/>
<div class="header">
    <i class="fa fa-facebook custom" aria-hidden="true"></i>
    <i class="fa fa-twitter custom" aria-hidden="true"></i>
    <i class="fa fa-instagram custom" aria-hidden="true"></i>
    <i class="fa fa-google-plus custom" aria-hidden="true"></i>
</div>