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-flow
is a shorthand of flex-direction and flex-wrap.flex-flow: <‘flex-direction’> || <‘flex-wrap’>
justify-content
defines the alignment along the main axisalign-items
is for cross-axis alignment- Similar to how
justify-content
aligns individual items within the main-axis,align-content
aligns space in the cross-axis
Attributes for items
- order
- flex-grow
- flex-shrink
- flex-basis
- flex
- align-self
order
with a smaller number would be in the front. By default is 0, however, -1 is ahead of 0flex-grow
enables the item to growflex-shrink
enables the item to shinkflex-basis
defines the default size of an element before the remaining space is distributedflex
is the shorthand forflex-grow
,flex-shrink
andflex-basis
combined. Default is0 1 auto
align-self
allows 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/