align icon on top of text inside button tag

北城余情 提交于 2021-01-28 10:22:59

问题


How can I align the icon inside a button tag to the top of the text, it is currently on the left side of the text. I can't figure out how.

Here is the code

<div class='nav'>
  <button class="home btn">
      <i class="btnIcon fa fa-home"></i>
       <span>HOME</span>
    </button>
</div>

回答1:


The simplest method would be to just declare the span as display:block

span {
  display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class='nav'>
  <button class="home btn">
  <i class="btnIcon fa fa-home"></i>
   <span>HOME</span>
</button>
</div>

Or use Flexbox and column layout

.btn.vertical {
  display: flex;
  flex-direction: column;
  align-items: center;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class='nav'>
  <button class="home btn vertical">
  <i class="btnIcon fa fa-home"></i>
   <span>HOME</span>
</button>
</div>


来源:https://stackoverflow.com/questions/46847894/align-icon-on-top-of-text-inside-button-tag

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