-
Layout core
: Stacks from the top left (box model)
- How?
- block
- inline
- How?
-
Methods to change the layout flow
- float
- position
- flex: flexible box
Before
flex,floatandpositionhad to be specified for layout
containeritem
<style>
.container {
display: flex;
}
</style>
<div class="container">
<div class="item"></div>
<div class="item"></div>
</div>-
-
main axis: Main axis
- Horizontal axis when
flex-direction: row; - Vertical axis when
flex-direction: column; - Vertical axis going from bottom to top when
flex-direction: column-reverse; - Horizontal axis going from right to left when
flex-direction: row-reverse;
- Horizontal axis when
-
cross axis: Cross axis
-
- All items are arranged based on the
main axis- The default is
row - If set to
row-reverse, arrangement starts from the right end
- The default is
- All
itemsare arranged based on row by defaultflex-direction: Default set torowvalue
- All
itemsfill thecross axis- They fill the entire height
- Because
align-items: stretch;is the default value
- Because
- They fill the entire height
- All
itemstake up width equal to their own width or content area- In some cases, it can be smaller than their specified width
- Because
flex-wrap: nowrapis the default value - ex) When the total width of all items is less than the container width
- Because
- In some cases, it can be smaller than their specified width
- Each area occupies space equal to its content size / width
- It can be even smaller!
- All areas fill the cross axis
- Default value
nowrap- Forces everything into one line
wrap- Each item takes its own width and wraps to the next line when there's no room
- Prevents overflow!
wrap-reverse- Items wrap round to additional lines in reverse
flex-growdivides and distributes the remaining width by ratio
- Default value
0
Shorthand property for
flex-directionandflex-wrap
Aligns based on the main axis
- Default value:
flex-start flex-startflex-endcenterspace-aroundspace-betweenspace-evenly
Aligns based on the cross axis
-
stretch: Default value
-
flex-start: Top alignment
-
flex-end: Bottom alignment
-
baseline: items are aligned such as their baselines
-
center: Center alignment
Sets the distribution of space between and around content items along a flexbox's cross-axis or a grid's block axis
align-content has no effect when there is only one line of flex items!
Can define the order of items
- Default value:
0 - Can have negative values
Can specify alignment directly on an item
flex allows margin-top: auto!
-
justify - main axis
-
align - cross axis
-
content - multiple lines
-
items - single line
-
self - individual element






