Using Flexbox, how do you distribute items equally inside a container?
Experience Level: Junior
Tags: CSSFlexbox
Answer
To distribute items equally on a line, set styles to justify-content: space-around
or justify-content: space-between
on the flex container.
To distribute items equally in the column, set styles justify-content: space-around
or justify-content: space-between
on the flex container. This would however display the items on a line. To display them in a column, you need to change the flex item flow direction to column. In order to do that, set styles flex-direction: column
on the flex container.
CSS - Horizontal direction
div {
display: flex;
justify-content: space-around;
}
CSS - Vertical direction
div {
display: flex;
justify-direction: column;
justify-content: spacing-around;
}
Related Flexbox job interview questions
What is a flex-direction property used for and what values can it have?
CSSFlexbox JuniorWhat is a difference between display: flex and display: inline-flex?
CSSFlexbox JuniorWhat CSS property does the value flex-end belong to and when would you use it?
CSSFlexbox JuniorUsing Flexbox, how can you align elements to right?
CSSFlexbox JuniorWhat does justify-content CSS property do and what values can it have?
CSSFlexbox Junior