彈性盒模型(flex-box)

彈性盒模型(display:flex)

在我們做移動端項目的時候,彈性盒模型經常會用到,初學者經常會搞不清它的屬性。下面主要了解一下彈性盒子的五個屬性。

1. flex-direction:指定彈性子元素在父容器中的位置

  • row:左對齊
  • row-reverse:右對齊
  • column:縱向對齊,即從上向下排列
  • column-reverse:反轉縱向對齊,即從下向上排列

下面展示效果
flex-direction: row;

flex-direction: row-reverse;
在這裏插入圖片描述
flex-direction: column;
在這裏插入圖片描述
flex-direction: column-reverse;
在這裏插入圖片描述

2. justify-content:內容對齊

  • flex-start:左對齊
  • flex-end:右對齊
  • center:居中
  • space-between:平均分佈
  • space-around:平均分佈並且兩邊有一半的間隔空間

下面展示效果
justify-content:flex-start
在這裏插入圖片描述
justify-content:flex-end
在這裏插入圖片描述
justify-content:center
在這裏插入圖片描述
justify-content:space-between
在這裏插入圖片描述
justify-content:space-around
在這裏插入圖片描述

3. align-items:縱軸上的對齊方式

  • flex-start:左對齊
  • flex-end:右對齊
  • center:居中
  • baseline:基線對齊
  • stretch:auto默認

下面展示效果
align-items:flex-start
在這裏插入圖片描述
align-items:flex-end
在這裏插入圖片描述
align-items:center
在這裏插入圖片描述
align-items:baseline
在這裏插入圖片描述
align-items:stretch
在這裏插入圖片描述

4.flex-wrap:子元素換行方式

  • nowrap:默認單行
  • wrap:多行
  • wrap-reverse:翻轉多行
  • initial
  • inherit:繼承

下面展示效果
flex-wrap:nowrap
在這裏插入圖片描述
flex-wrap:wrap
在這裏插入圖片描述
flex-wrap:wrap-reverse
在這裏插入圖片描述

5.align-content:用於修改flex-wrap屬性,修改各行對齊方式

  • flex-start
  • flex-end
  • center
  • space-bewteen
  • space-around
  • stretch:默認

下面展示效果
align-content:flex-start
在這裏插入圖片描述
align-content:flex-end
在這裏插入圖片描述
align-content:center
在這裏插入圖片描述
align-content:space-bewteen
在這裏插入圖片描述
align-content:space-around
在這裏插入圖片描述

上面五個屬性是給彈性盒子設置的屬性,那麼彈性子元素的屬性呢?

  1. order 屬性值爲整數,數字越小,越靠前。
  2. align-self:縱軸
  3. flex:用於指定彈性子元素之間怎麼分配空間。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章