Chapter 15. CSS: Layout – Flex Box
Flex Box
Original
item 1
item 2
item 3
item 4
item 5
item 6
display: flex
item 1
item 2
item 3
item 4
item 5
item 6
flex-direction
flex-direction:row
item 1
item 2
item 3
item 4
item 5
item 6
flex-direction:row-reverse
item 1
item 2
item 3
item 4
item 5
item 6
flex-direction:column
item 1
item 2
item 3
item 4
item 5
item 6
flex-direction:column-reverse
item 1
item 2
item 3
item 4
item 5
item 6
flex-wrap
flex-wrap: nowrap
item 1
item 2
item 3
item 4
item 5
item 6
item 7
flex-wrap: no-wrap
item 1
item 2
item 3
item 4
item 5
item 6
item 7
flex-wrap: wrap-reverse
item 1
item 2
item 3
item 4
item 5
item 6
item 7
justify-content
Original Position
justify-content: flex-start
justify-content: center
justify-content: flex-end
justify-content: spece-between
justify-content: spece-around
align-items
Original Position
align-items: flex-start
align-items: center
align-items: flex-end
align-items: stretch
align-items: baseline
align-content
Original Position
item 1
item 2
item 3
item 4
item 5
item 6
item 7
item 8
item 9
item 10
item 11
item 12
align-content: flex-start
item 1
item 2
item 3
item 4
item 5
item 6
item 7
item 8
item 9
item 10
item 11
item 12
align-content: center
item 1
item 2
item 3
item 4
item 5
item 6
item 7
item 8
item 9
item 10
item 11
item 12
align-content: flex-end
item 1
item 2
item 3
item 4
item 5
item 6
item 7
item 8
item 9
item 10
item 11
item 12
align-content: stretch
item 1
item 2
item 3
item 4
item 5
item 6
item 7
item 8
item 9
item 10
item 11
item 12
align-content: space-between
item 1
item 2
item 3
item 4
item 5
item 6
item 7
item 8
item 9
item 10
item 11
item 12
align-content: space-around
item 1
item 2
item 3
item 4
item 5
item 6
item 7
item 8
item 9
item 10
item 11
item 12
align-self
Original Position
align-self: flex-start
align-self: center
align-self: flex-end
align-self: stretch (align-items:center) @ Parent
align-self: baseline (align-items:center) @ Parent
flex-grow
Original Flex Item Size
Grow Evenly
flex-grow: 1
flex-grow: 1
flex-grow: 1
Grow Red and Blue with the Same Ratio
flex-grow: 0
flex-grow: 1
flex-grow: 1
Grow Red and Blue with 1:2 Ratio
flex-grow: 0
flex-grow: 1
flex-grow: 2
Grow Blue Only
flex-grow: 0
flex-grow: 0
flex-grow: 1
flex-shrink
Flex Item Size with No Shrink
Shrink Evenly
flex-shrink: 1
flex-shrink: 1
flex-shrink: 1
Shrink Red and Blue with the Same Ratio
flex-shrink: 0
flex-shrink: 1
flex-shrink: 1
Shrink Red and Blue with 1:2 Ratio
flex-shrink: 0
flex-shrink: 1
flex-shrink: 2
Shrink Blue Only
flex-shrink: 0
flex-shrink: 0
flex-shrink: 1
flex-basis
Original Flex Item Size - Horizontal Layout
Horizontal Layout with flex-basis
flex-basis: 25%
flex-basis: 25%
flex-basis: 50%
Original Flex Item Size - Vertical Layout
Vertical Layout with flex-basis
flex-basis: 25%
flex-basis: 25%
flex-basis: 50%
margin: auto with Flex Box
- Original Position
- margin-left & right: auto
- margin-left: auto
- margin-top & bottom: auto
- margin: auto
- margin-left, top & bottom: auto
- margin-top: auto
- margin-top, left & right: auto
- margin-top & left: auto
Inline Flex Box
Flex Box
Inline Flex Box
Nested Flex Box
Layout 1
Layout 1 with Content in the Center
Layout 2
Layout 3