display:flex; 布局
- 給父元素添加
display:flex;display:-webkit-flex;flex-direction: row | row-reverse | column | column-reverse; 屬性決定主軸的方向(即項目的排列方向)row(默認值):主軸為水平方向,起點在左端。row-reverse:主軸為水平方向,起點在右端。column:主軸為垂直方向,起點在上沿。column-reverse:主軸為垂直方向,起點在下沿。flex-wrap: nowrap | wrap | wrap-reverse;nowrap(默認):不換行。wrap:換行,第一行在上方。flex-flow: <flex-direction> || <flex-wrap>; row nowrapjustify-content: flex-start | flex-end | center | space-between | space-around;flex-start(默認值):左對齊flex-end:右對齊center: 居中space-between:兩端對齊,項目之間的間隔都相等。space-around:每個項目兩側的間隔相等。所以,項目之間的間隔比項目與邊框的間隔大一倍。align-items: flex-start | flex-end | center | baseline | stretch;flex-start:交叉軸的起點對齊。flex-end:交叉軸的終點對齊。center:交叉軸的中點對齊。baseline: 項目的第一行文字的基線對齊。stretch(默認值):如果項目未設置高度或設為auto,將占滿整個容器的高度。
- 給子元素添加
order 屬性定義項目的排列順序。數值越小,排列越靠前,默認為0。flex-grow 屬性定義項目的放大比例,默認為0,即如果存在剩餘空間,也不放大。flex-shrink 屬性定義了項目的縮小比例,默認為1,即如果空間不足,該項目將縮小。flex-basis 屬性定義了在分配多餘空間之前,項目占據的主軸空間(main size)。flex 屬性是flex-grow, flex-shrink 和 flex-basis的簡寫,默認值為0 1 auto。後兩個屬性可選。0 0 30p xalign-self
常用布局:
sticker footer :容器有最小高度,內容超出最小高度自動撐開,容器內底部有一個固定元素item,容器內沒有內容時,item在容器底部,內容超出容器後,容器被撐開,item依然在底部。
box{display:flex;flex-direction:column;}.top{flex:1;}
第二種布局
<div class="box2"><div class="content2"><div class="inner"><p>fsf</p><p>fsf</p><p>fsf</p></div></div><div class="footer2">X</div></div>.box2{border:2px solid red;border-radius:2px;width:200px;height:200px;margin:20px auto 0;overflow: auto;}.content2{width:100%;min-height:100%;}.inner{padding-bottom:35px;}.footer2{position:relative;margin:-40px auto;clear: both;}
最後更新:2017-07-26 11:03:18