在中间对齐font-awesome图标

时间:2018-06-05 13:09:41

标签: html css font-awesome vertical-alignment

我正在使用字体真棒图标。不知怎的,我似乎无法让它们在中间垂直对齐。

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

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

仍然无法正常工作。

3 个答案:

答案 0 :(得分:2)

你可以使用align-items:center with 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>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

通过添加#icons i

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

答案 2 :(得分:1)

line-height添加到 #icons id

#icons i {

  line-height: 30px;

}
相关问题