You are on page 1of 1

Devarsenal

Flexbox cheat sheet 1


Flex container (Parent)

1 2 3

Flex items (Children)

Parent container properties


display flex-wrap
This creates a flex container. .container {
Elements under the container will display: flex; 1 2 3 4
turn into flex items. }

5 6 7
flex direction column
row 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 in the next
row-reverse
row or column.

column-reverse .container {
display: flex;

Flex direction defines the axis in which the container


flex-wrap: nowrap | wrap | wrap-reverse;
}
should stack the flex items. Horizontal rows or vertical
columns.
nowrap (default value): nowrap value specifies the flex
.container { items not to wrap.
display: flex;
wrap: wrap value specifies the flex items to wrap if required.
flex-direction: row | row-reverse | column | column-reverse;
} wrap-reverse: wrap-reverse specifies the flex items to wrap
in the reverse order if required.
row (default value): row value stacks the flex items in the
horizontal direction from left to right.

row-reverse: row-reverse value stacks the flex items in


flex-flow
the horizontal direction from right to left. This property is a shorthand for the flex-direction
column: column value stacks the flex items in the vertical property and the flex-wrap property.
direction from top to bottom.
.container {
column-reverse: column-reverse value stacks the flex display: flex;
items in the vertical direction from bottom to top. flex-flow: row wrap;
}

justify-content
The justify-content property aligns the flex items align-content
along the main axis.

The align-content property is similar to the


For flex items in row, the justify-content property align-items property, but this aligns flex lines instead
will align the item in the horizontal direction.

of the flex items across the cross axis. This works only
For flex items in column, the justify-content when there are multiple lines of flex items.
property will align the item in the vertical direction.
flex-start flex-end

flex-start

flex-end
center stretch

center

space-between
space-around

space-between

space-around
.container {
display: flex;
flex-direction: flex-start | flex-end | center | space-between | space-around |
space-evenly;

space-evenly }

flex-start: Lines of flex items are stacked at the start of the


flex container.
flex-end: Lines of flex items are stacked at the end of the
flex container.
.container {
display: flex; center: Lines of flex items are stacked at the center of the
flex-direction: flex-start | flex-end | center | space-between | space-around |
flex container.
space-evenly;
} stretch: Lines of flex items are stretched to fill up the flex
container.
flex-start (default value): Flex items are stacked at the
beggining of the flex container. space-between: Lines of flex items arranged evenly in the
flex container
flex-end: Flex items are stacked at the end of the flex

container. space-around: Lines of flex items arranged in the flex


center: Flex items are stacked at the center of the flex
container, with half space on either ends of the flex
container. container.
space-between: Flex items are evenly spaced in a line. space-evenly: Lines of flex items arranged in the flex
container, with equal space around them.
space-around: Flex items are evenly distributed with equal

space around them.


space-evenly: Flex items are distributed in a way that the

spacing between any two adjacent items are equal.


Perfect Centering of elements
This trick can solve the most common problem
align-items face by any developer.

The align-items property aligns the flex items along Centering


the cross axis.

For flex items in row, the align-items property will align


items in vertical direction from top to bottom.

For flex items in column, the align-items property will


align items in horizontal direction from left to right.
.container {
display: flex;
flex-start flex-end height: 50px;
justify-direction: center;
align-tems: center;
}

center stretch

baseline

text text text text

.container {
display: flex;
flex-direction: stretch | flex-start | flex-end | center | baseline;
}

stretch (Default value): Flex items are stretched to fill up the


flex container.
flex-start: Flex items are stacked at top of the flex
container.
flex-end: Flex items are stacked at bottom of the flex

container.
center: Flex items are stacked at middle of the flex

container.
baseline: Flex items are aligned such that individual
baselines align at the same level. The baselines are
calculated by considering the size of the content inside the
container. In the above example, the baseline is taken with Copyright © 2021 by Devarsenal

respect to the text in individual items. All rights reserved. No part of this guide

may be reproduced or used in any

manner without written permission of the

copyright owner except for the

Contact - support@devarsenal.io Beginner to Advanced HTML5 and CSS3


quotations in a review.

Referral code - https://www.udemy.com/course/beginner-to-advanced-html5-css3/?referralCode=86B48B5D2E398D20182A

You might also like