Flex Box Basic
Get out of nightmare that positioning elements with CSS.
What is Flexbox Layout
// todo
Terminology
The box, we call it flex container. All children are flex items.
X-axis of the container called main axis, Y-axis is named cross axis.
Start of main axis is main start, end of the main axis is main end.
Attributes for container:
- flex-direction
- flex-wrap
- flex-flow
- justify-content
- align-items
- align-content
- The direction of rows is controlled by flex-direction
- Keep the row won’t break, using
flex-wrap: nowrap; -
flex-flowis a shorthand of flex-direction and flex-wrap.flex-flow: <‘flex-direction’> || <‘flex-wrap’> justify-contentdefines the alignment along the main axisalign-itemsis for cross-axis alignment- Similar to how
justify-contentaligns individual items within the main-axis,align-contentaligns space in the cross-axis
Attributes for items
- order
- flex-grow
- flex-shrink
- flex-basis
- flex
- align-self
orderwith a smaller number would be in the front. By default is 0, however, -1 is ahead of 0flex-growenables the item to growflex-shrinkenables the item to shinkflex-basisdefines the default size of an element before the remaining space is distributedflexis the shorthand forflex-grow,flex-shrinkandflex-basiscombined. Default is0 1 autoalign-selfallows the default alignment to be overridden for individual flex items
Conclusion
Flexbox layout is most appropriate to the components of an application, and small-scale layouts, while the Grid layout is intended for larger scale layouts.
As per https://css-tricks.com/snippets/css/a-guide-to-flexbox/