以下是我的html和css代碼。如何使用flexbox將兩個<a/>與中心對齊?
.tab {
display: flex;
self-align: center;
align-items: center;
margin: auto;
width: 100%;
border: 1px solid red;
}
.section-title {
display: flex;
margin: 5px;
}
.label {
display: flex;
padding: 10px;
}
.label-a {
color: white;
background-color: green;
}
.label-b {
color: white;
background-color: orange;
}
<div class=tab>
<a class=section-title>
<div class="label label-a">Tab a</div>
</a>
<a class=section-title>
<div class="label label-b">Tab b</div>
</a>
</div>
我的目標是使綠色和橙色框移動到紅色邊框的盒子的中心,就像這樣:
我已經嘗試了一些東西,比如:
1)使用margin: auto
2)確保.tab
寬度爲100%。
3).section-title
和display
財產
.label
使用Flexbox的爲什麼,因爲我希望對齊不起作用?是否因爲a
不是塊元素?