Flexbox¶
Estimated time to read: 2 minutes
Concepts¶
-
CSS flexbox is a one-dimensional layout model that allows you to arrange elements in rows and columns within a container:
-
flex container: an HTML element with a flex layout. apply
display: flexto an element to make it a flex container -
flex item: the direct children of a flex container.
-
-
Every flex container has two axes:
-
The main axis.(horizontal), defined by flex-direction
-
The cross axis.(vertical)
-
-
flex properties:
-
flex-direction: row(default), row-reverse, column, column-reverse -
justify-content: flex-start flex-end center space-between space-around space-evenlyaligns the child elements along the main axis of the flex container. -
align-items: stretchdistribute the child elements along the cross axis -
flex-wrap: nowrap, wrap( allow the items to wrap to the next row or column), wrap-reverse -
flex-flow: column wrap-reverse;shorthand property forflex-directionandflex-wrap -
align-self:individual flex item -
order: 0( they appear in the order they're written in the HTML, Items with lower order values appear first) -
flex-grow: 0|1|2...how much a flex item should grow relative to the rest of the flex items if there is extra space available inside the parent flex container. -
flex-shrinkIt dictates how much a flex item should shrink relative to the other flex items when there isn't enough space inside the parent flex container.
-