CSS Flex - flex-direction (row or column)

Css Flex Align Content

About

The flex-direction layout the children of a flex container in:

  • row
  • or column

The block layout have also column layout

flex-direction is part of what's called the flex-flow.

Example

This three examples are based on a row of div an shows the effect of the flex-direction value.

Note: The examples share this HTML and CSS to create a row of cells.

  • the same HTML (a container with a serie of cell)
<div class="flex">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
</div>
  • The same css:
    • for the first div container: a flex
    • for the item children, a box
.flex {
  display: flex;
  margin:2rem;
}
.item {
  width: 80px;
  height: 20px;
  background-color: SkyBlue;
  border: 1px solid #e7e7e7;
  text-align: center;
  box-sizing: border-box;
}

default: row

The default value is to layout as row the children.

The width is not taken into account. If you want, you should set the flex-wrap property.

.flex {
  width: 300px;
}

row

.flex {
  flex-direction: row;
}

column

.flex {
  flex-direction: column;
}





Discover More
Css Flex Align Content
CSS - Flex Box

flex is a layout model that lays out object in a single axis focused on space distribution and content alignment. flex means: flexible layout as flexible size Flex layout is superficially similar...
Flex Vs Grid Css
CSS - Layout Mode (Visual Formatting Model)

This page is the layout available in CSS. A layout system is an algorithm which determine the size and position of boxes based on their relationships with their sibling and ancestor boxes: In Css,...
Css Flex Align Content
CSS flex-flow property

CSS flex-flow property
Css Flex Align Content
Flex - flex-wrap (Single Line or Multi-Line)

A flex container can be either single-line or multi-line, depending on the flex-wrap property. flex-wrap: nowrap: (Default)A single-line flex container lays out all of its children in a single line,...



Share this page:
Follow us:
Task Runner