A guide to understanding flexbox in depth with practical examples
- a recently new CSS standard that simplifies adding desired layouts to page content
- provides an efficient way to layout, align, and distributed spacing among elements in the DOM
- Flex Container: The parent container to which you set flexible display to.
- Flex Item(s): The child elements that are residing inside the parent flexible container.
- controls the direction of flex container items
flex-directionproperty values:
- controls the flow of flex items and whether or not they should be forced into a single line or wrapped in multiple lines (despite the number of flex items)
flex-wrapproperty values:
- a shortcut to using both flex-direction and flex-wrap values together(i.e.,
flex-flow: row wrap) flex-flowproperty values:
- a more enhanced version of text-align for all DOM elements to align elements in the main axis(horizontally)
justify-contentproperty values:
- a more enhanced version of text-align for all DOM elements to align elements in the cross axis(vertically)
align-itemsproperty values:
- controls how flex items are aligned in multi line flex containers
align-contentproperty values:
- controls the order of flex items to be displayed
- default value is 0, but can take in both positive and negative integer values
- works similar to z-index, order of content goes from lowest order integer to highest
orderproperty values:
- controls the amount of space a flex item can take in, squeeze in based on available space
- flex grow expands content to full extent of parent element horizontally
- flex shrink shrinks content to its default size if there is available space or if there is no space, it shrinks content to fit within parent element
- default value is 0, but it can also be any positive integer
flex-growandflex-shrinkproperty values:
- specifies an initial size of flex items, but it can altered with flex-grow and flex-shrink
- default value is 'auto,' but it can also be any size attribute(px, em, % etc.)
flex-basisproperty values:
- a shorthand for flex-shrink, flex-grow and flex-basis all together
- an simple example could be
flex: 0 1 auto, 0 is flex-grow, 1 is flex-shrink, and auto is flex-basis flexproperty values:
- helps to align specific flex items to align differently compared to its siblings
align-selfproperty values:
- helps with auto margin behavior for flex items