在中间对齐超棒的字体图标

align font-awesome icon in the middle

我正在使用超赞的字体图标。不知何故,我似乎无法让它们在中间垂直对齐。

白色部分必须在黑色部分的中间。我用codepen做了一支笔。 https://codepen.io/kevin-bobsen/pen/qKZKRX 我试过了:

vertical-align:middle;
text-align:center;

仍然无法正常工作。

通过添加 line-height:30px

修改 #icons i
 #icons i {
        background: black;
        color: white;
        text-align: center;
        height: 100%;
        line-height: 30px;
    }

好吧,您可以将 align-items:center 与 display:inline-flex 一起用于您的解决方案,就像我在以下代码中所做的那样。请看

#main {
height:400px;
width:600px;
border:1px solid black;
margin:0 auto;
}
#pic{
width:300px;
height:100%;
float:left;
}

#bio{
width:300px;
height:100%;
float:right;
background:grey;
}

#avatar{
  width:100%;
  height:50px;
  margin-left:30px;
  margin-top:50px;
  display:inline-block;
}
#avatar img{
  width:50px;
  height:50px;

  border-radius:360px;
}

#avatar span{
  font-size:18px;
  margin-left:30px;
  position:absolute;
  margin-top:15px;

}

#icons{
  width:90%;
  height:30px;
  display:inline-block;
  margin-left:5%;
  font-size:15px;
  margin-right:5%;
  background:red;
}

#icons i{
background:black;
color:white;
text-align:center;
height:100%;
display: inline-flex;
align-items: center;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<div id="main">
<div id="pic">
</div>
<div id="bio">
<div id="avatar">
  <img style="vertical-align:middle"     src="https://placehold.it/60x60">
  <span style="">keVin#1234</span>
</div>
<div id="icons">
<i class="fab fa-accusoft"> </i>
  <i class="fab fa-accusoft"> </i>
  <i class="fab fa-accusoft"> </i>
</div>
</div>
</div>
</div>

line-height 添加到您的 #icons id:

#icons i {

  line-height: 30px;

}