如何将按钮标记内的图标与文本顶部对齐,它当前位于文本的左侧。我无法弄清楚如何。
这是代码
<div class='nav'>
<button class="home btn">
<i class="btnIcon fa fa-home"></i>
<span>HOME</span>
</button>
</div>
&#13;
答案 0 :(得分:4)
最简单的方法是将范围声明为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>
或使用Flexbox和列布局
.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>