This creates a flex container. Element under the container will turn into flex items.
.container { display: flex; }
Flex direction defines the axis in which the container should stack the flex items.
.container { display: flex; flex-direction: row | row-reverse | column | column-reverse; }
The justify-content property aligns the flex items along the main axis.
For flex items in a row: The justify-content property will align the items in the horizontal direction..container { display: flex; justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly; }
The align-items property aligns the flex items along the cross axis.
For flex items in a row: The align-items property will align items in vertical direction from top to bottom.2
4
.container { display: flex; align-items: stretch | flex-start | flex-end | center | baseline; }
Default behaviour of flexbox tries to fit the flex items well within a single line. The flex-wrap property enables us to wrap the items into the next row or column.
For flex items in a row: The items will wrap down next row..container { display: flex; flex-wrap: nowrap (default) | wrap | wrap-reverse; }
This property is a shorthand for flex-direction property and the flex-wrap property.
.container { display: flex; flex-flow: row wrap; }
The align-content property is similar to the align-items property, but this aligns flex lines instead of flex items across the cross axis. This works only when there are multiple lines of flex items.
.container { display: flex; align-content: flex-start | flex-end | center | stretch | space-between | space-around; }
This trick can solve the most common problem faced by developers.
Centered
.container { display: flex; height: 100px; justify-content: center; align-items: center; }
1234
The order property defines the order in which the flex items are to be arranged. By default, flex items will be arranged in the source order. The initial value of order is "0" - zero.
123123
This defines how much a flex item can grow inside the flex container. The default value is 0 (zero). In row-1, the first and the last are of equal sizes, but thesecond item is twice as big as the first/last item.
123456|9
The flex-shrink property defines how a flex item should shrink relative to the rest of the flex items. Note: the 4th item with a shrink value of 0 grew while the 5th item with a shrink value of 3 is one-third the size of other items.
1234
The flex-basis property defines the initial length of an individual flex-item. Note item 1,2 & 4 are set to flex-basis of 50px and item 3 is set to 300px.
1234
The flex property is a shorthand property for defining flex-grow, flex-shrink, and the flex-basis properties. The shorthand property is highly recommended over defining individual properties.
The align-self property sets the alignment property for the selected flex item inside the flex-container. This property overrides the default alignment property assigned by the container's align-items property.
1234
The align-self property works similarly for flex-start, flex-end, center, space-between, space-around and space-evenly properties.