flex屬性主要分成容器
和子層的物件
為什麼要分兩種
因為子層物件
本身也可以是容器
讓更下層的物件
使用
所以flex屬性才需要區分成容器
和物件
再來是flex本身就是非常強大的RWD排版語法
flex練熟的話就可以不用bootstrap也能排出很好的RWD版面(不考慮細節美化)
目前主流的Web App很多都已經改成flex排版
可以參考:
web
,css
, flex
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
.flex-container {
display: flex;
}
<div class="flex-container">
<div class="flex-items">1</div>
<div class="flex-items">2</div>
<div class="flex-items">3</div>
</div>
.flex-container {
display: inline-flex;
}
.flex-items {
flex-grow: 1;
}
flex-flow: flex-direction flex-wrap|initial|inherit;
flex-direction: row|row-reverse|column|column-reverse|initial|inherit;
flex-direction: row;
row
- 左上開始往右row-reverse
- 右上開始往左column
- 左上開始往下reverse
左下開始往上flex-wrap: nowrap|wrap|wrap-reverse|initial|inherit;
flex-wrap: nowrap;
nowrap
- 不換行wrap
- 換行wrap-reverse
- 從左下往右開始,再往上換行justify-content: flex-start|flex-end|center|space-between|space-around|initial|inherit;
justify-content: flex-start;
flex-start
- 靠左flex-end
- 靠右center
- 置中space-between
- 分散(左右不留空)space-around
- 平均分散(左右留空)align-items: stretch|center|flex-start|flex-end|baseline|initial|inherit;
align-items: stretch;
stretch
- 上下高度自動滿版center
- 垂直置中不滿版flex-start
- 置頂不滿版flex-end
- 置底不滿版baseline
- 以文字基線來垂直置中align-content: stretch|center|flex-start|flex-end|space-between|space-around|initial|inherit;
align-content: stretch;
flex-wrap
排版完,再用排版完的區域調整對齊位置stretch
- 每一行都靠上,行分散(沒設定高度時會自動滿版)center
- 全部往父容器中心靠flex-start
- 全部往上靠flex-end
- 全部往下靠space-between
- 上下分散(上下不留空)space-around
- 上下平均分散(上下留空)order: number|initial|inherit;
0
flex: 0 1 auto;
flex-grow: number|initial|inherit;
flex-grow: 0;
1
且有設定基礎寬度時,不足寬度會自動加寬滿版,超過寬度時會自動換行,算是非常強大的rwd語法flex-shrink: number|initial|inherit;
flex-shrink: 1;
flex-basis: number|auto|initial|inherit;
flex-basis: auto
align-self: auto|stretch|center|flex-start|flex-end|baseline|initial|inherit;
align-self: auto;