Grid System
HTML / CSS Layout
Layout core
: Stacks from the top left (box model)
How?
block
inline
Methods to change the layout flow
float
position
flex: flexible box
flex
Before
flex,floatandpositionhad to be specified for layout
Key Concepts of flex
containeritem
Axes
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;
cross axis: Cross axis
When Defining flex
All items are arranged based on the
main axisThe default is
rowIf set to
row-reverse, arrangement starts from the right end
All
itemsare arranged based on row by defaultflex-direction: Default set torowvalue
All
itemsfill thecross axisThey fill the entire height
Because
align-items: stretch;is the default value
All
itemstake up width equal to their own width or content areaIn some cases, it can be smaller than their specified width
Because
flex-wrap: nowrapis the default valueex) When the total width of all items is less than the container width
Each area occupies space equal to its content size / width
It can be even smaller!
All areas fill the cross axis
flex Properties
1. flex-wrap
Default value
nowrapForces everything into one line
wrapEach item takes its own width and wraps to the next line when there's no room
Prevents overflow!
wrap-reverseItems wrap round to additional lines in reverse
2. flex-grow
flex-growdivides and distributes the remaining width by ratio
Default value
0
3. flex-flow
Shorthand property for
flex-directionandflex-wrap
Default value
row wraprow-reverse nowrapcolumn wrap-reversecolumn wrap
4. justify-content
Aligns based on the main axis
Default value:
flex-startflex-startflex-endcenterspace-aroundspace-betweenspace-evenly
5. align-items
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
6. align-content
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!
Default value:
stretchflex-startflex-endcenterspace-betweenspace-around
7. order
Can define the order of items
Default value:
0Can have negative values
8. align-self
Can specify alignment directly on an item
flex allows margin-top: auto!
Wrap-up
justify - main axis
align - cross axis
content - multiple lines
items - single line
self - individual element
Last updated