若希望能對 Main Axis 方向靠左,可使用 justify-content flex-start 設定。
Version
CSS 3
Column Left

子層 item 靠左對齊,且內容 123 從左開始。
<template lang='pug'>
section
div 1
div 2
div 3
</template>
<style lang='stylus' scoped>
section
display flex
flex-direction row
justify-content flex-start
width 100%
height 97vh
div
width 50px
height 50px
margin 10px
</style>
第 9 行
section
display flex
flex-direction row
justify-content flex-start
width 100%
height 97vh
設定 section style:
display flex:設定子層 item 使用 Flexboxflex-direction row:表示水平由左至右,main axis 為 row,這也是 Flexbox 預設值justify-content flex-start:因為由左至右,所以 item 也是靠左對齊width 100%:設定section寬度height 97vh:設定section高度
16 行
div
width 50px
height 50px
margin 10px
設定 div style:
width 50px:設定div寬度height 50px:設定div高度margin 10px:設定divmargin
Content Left

子層 item 水平靠左,且內容 123 也水平靠左。
<template lang='pug'>
section
div 1
div 2
div 3
</template>
<style lang='stylus' scoped>
section
display flex
flex-direction row
width 100%
height 97vh
div
display flex
justify-content flex-start
width 50px
height 50px
margin 10px
</style>
第 9 行
section
display flex
flex-direction row
width 100%
height 97vh
設定 section style:
display flex:設定子層 item 使用 Flexboxflex-direction row:表示水平由左至右,main axis 為 row,這也是 Flexbox 預設值width 100%:設定section寬度height 97vh:設定section高度
15 行
div
display flex
justify-content flex-start
width 50px
height 50px
margin 10px
設定 div style:
display flex:在每個div再度使用 Flexboxjustify-content flex-start:讓div內 content 水平靠左width 50px:設定div寬度height 50px:設定div高度margin 10px:設定divmargin
Conclusion
- 若
flex-direction設定為column,則 main axis 為 column,justify-content則對 column 方向對齊 justify-content flex-start有兩種用途:若用在父層則是將所有 column 水平靠左;若用在子層則是將 content 水平靠左