HTML
<div class="ly">
<div class="ly__item">xxx</div>
<div class="ly__item">xxx</div>
<div class="ly__item">xxx</div>
<div class="ly__item">xxx</div>
</div>
多個元素在一行
CSS
.ly{
display: flex;
}
多個元素水平居中對齊
.ly{
display: flex;
justify-content: center;
}
多個元素水平兩端對齊
.ly{
display: flex;
justify-content: space-between;
}
多行多個元素水平兩端對齊
.ly{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
多個元素在一行嵌洼,某個元素占據(jù)剩余部分
.ly{
display: flex;
}
//給占據(jù)剩余部分的元素加該類名
.ly__item--fill{
flex-grow: 1;
}
多個元素水平居右對齊
.ly{
display: flex;
justify-content: flex-end;
}
多個元素垂直居中
.ly{
display: flex;
align-items: center;
}
多個元素水平垂直居中對齊
.ly{
display: flex;
justify-content: center;
align-items: center;
}