採用Flex佈局的元素,稱爲Flex容器,簡稱」容器」。
注: **設了flex以後 子元素的float clear vertical-align屬性將失效
將元素轉爲彈性盒:display:flex**css
.box {
html
flex-direction: row | row-reverse | column | column-reverse;
ide
}
佈局
row(默認值):主軸爲水平方向,起點在左端。flex
row-reverse:主軸爲水平方向,起點在右端。spa
column:主軸爲垂直方向,起點在上沿。code
column-reverse:主軸爲垂直方向,起點在下沿。htm
.box{
繼承
flex-wrap: nowrap | wrap | wrap-reverse;
it
}
nowrap 默認不換行
wrap:換行,第一行在上方。
wrap-reverse:換行,第一行在下方。
.box {
justify-content: flex-start | flex-end | center | space-between | space-around;
}
flex-start(默認值):左對齊
flex-end:右對齊 center: 居中
space-between:兩端對齊,項目之間的間隔都相等。
space-around:每一個項目兩側的間隔相等。因此,項目之間的間隔比項目與邊框的間隔大一倍。
.box {
align-items: flex-start | flex-end | center | baseline | stretch;
}
flex-start:交叉軸的起點對齊。
flex-end:交叉軸的終點對齊。
center:交叉軸的中點對齊。
baseline: 項目的第一行文字的基線對齊。
stretch(默認值):若是項目未設置高度或設爲auto,將佔滿整個容器的高度。
***html***
<div class="container">
<div class="box box1">1</div>
<div class="box box2">2</div>
</div>
***css***
.container{
width: 100%;
height: 100px;
display: flex;
}
.box1{
background: pink;
width:100px;
}
.box2{
background: green;
flex:1;
}