Vertical align font awesome icon with text within <li>

。_饼干妹妹 提交于 2019-12-08 03:08:27

问题


I have a list that uses font awesome, hence its class is fa-ul :

<ul class='fa-ul'>
      <li class='dept'><i class='fa-li fa fa-stop'></i><span>Management</span></li>
      <li class='dept'><i class='fa-li fa fa-stop'></i><span>Something else</span></li>
</ul>

The associated CSS is :

li {
    font-size : 2em;
    margin: 1em 0;
}

I'd like the text and the stop-square to be vertically aligned. So far, it is not the case :

See screenshot:

I've tried to wrap the fa-icon and the text in a <div> element with vertical-align property set to middle, without success. Thanks for helping me.


回答1:


Use inline-blocks and do vertical-align: middle to make it right.

li {
    font-size : 2em;
    margin: 1em 0;
}

li > *{
  display: inline-block;
  vertical-align: middle;
  }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">

<ul class='fa-ul'>
      <li class='dept'><i class='fa-li fa fa-stop'></i><span>Management</span></li>
      <li class='dept'><i class='fa-li fa fa-stop'></i><span>Something else</span></li>
</ul>



回答2:


Use Line-Height

 li {
   font-size: 2em;
   margin: 1em 0;
   line-height: 40px;/*try changing this value*/
 }


来源:https://stackoverflow.com/questions/39145388/vertical-align-font-awesome-icon-with-text-within-li

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!