如何垂直对齐较小的 material 浮动按钮?
How can I align vertically a smaller material float button?
我有以下代码来创建一些浮动按钮:
<div class='history-buttons__container'>
<button mat-mini-fab>all</button>
<button mat-mini-fab>1y</button>
<button mat-mini-fab>6m</button>
<button mat-mini-fab>30d</button>
</div>
.history-buttons__container > button{
display: block;
margin-bottom: .5rem;
width: 2rem;
height: 2rem;
}
产生以下结果:
如果我删除了宽度和高度,它们看起来还不错:
由于这些元素在 diplay: block
中以垂直堆叠,我不能使用 vertical-align
。在缩小图标的同时如何使项目内的文本居中?
使用 flex,您可以轻松做到
.history-buttons__container {
display:flex;
flex-direction:column;
}
.history-buttons__container > button{
display: flex;
justify-content: center;
align-items: center;
margin-bottom: .5rem;
width: 2rem;
height: 2rem;
}
<div class='history-buttons__container'>
<button mat-mini-fab>all</button>
<button mat-mini-fab>1y</button>
<button mat-mini-fab>6m</button>
<button mat-mini-fab>30d</button>
</div>
我有以下代码来创建一些浮动按钮:
<div class='history-buttons__container'>
<button mat-mini-fab>all</button>
<button mat-mini-fab>1y</button>
<button mat-mini-fab>6m</button>
<button mat-mini-fab>30d</button>
</div>
.history-buttons__container > button{
display: block;
margin-bottom: .5rem;
width: 2rem;
height: 2rem;
}
产生以下结果:
如果我删除了宽度和高度,它们看起来还不错:
由于这些元素在 diplay: block
中以垂直堆叠,我不能使用 vertical-align
。在缩小图标的同时如何使项目内的文本居中?
使用 flex,您可以轻松做到
.history-buttons__container {
display:flex;
flex-direction:column;
}
.history-buttons__container > button{
display: flex;
justify-content: center;
align-items: center;
margin-bottom: .5rem;
width: 2rem;
height: 2rem;
}
<div class='history-buttons__container'>
<button mat-mini-fab>all</button>
<button mat-mini-fab>1y</button>
<button mat-mini-fab>6m</button>
<button mat-mini-fab>30d</button>
</div>