The main axis is used to position flex items with the following properties:
justify-content
Preview: Docs Loading link description
Preview: Docs Loading link description
Preview: Docs Loading link description
The cross axis is used to position flex items with the following properties:
align-items
align-content
The flex-direction property can accept four values:
row — elements will be positioned from left to right across the parent element starting from the top left corner (default).
row-reverse — elements will be positioned from right to left across the parent element starting from the top right corner.
column — elements will be positioned from top to bottom of the parent element starting from the top left corner.
column-reverse — elements will be positioned from the bottom to the top of the parent element starting from the bottom left corner.
body {
margin: 0;
border: 0;
font-family: 'Roboto Mono', monospace;
}
h1 {
font-size: 18px;
}
h2 {
font-size: 14px;
}
h1,
h2 {
text-align: center;
}
.container {
background-color: dodgerblue;
display: flex;
height: 600px;
}
.box {
background-color: whitesmoke;
border: 1px solid white;
width: 100px;
height: 100px;
}
#row {
}
#row-reverse {
}
#column {
}
#column-reverse {
}
<!DOCTYPE html>
<html>
<head>
<title>Direction</title>
<link href='style.css' rel='stylesheet' />
<link href='https://fonts.googleapis.com/css?family=Roboto+Mono' rel='stylesheet'>
</head>
<body>
<h1>Flex-Direction: Row</h1>
<div class='container' id='row'>
<div class='box'>
<h2>1</h2>
</div>
<div class='box'>
<h2>2</h2>
</div>
<div class='box'>
<h2>3</h2>
</div>
<div class='box'>
<h2>4</h2>
</div>
<div class='box'>
<h2>5</h2>
</div>
</div>
<h1>Flex-Direction: Row-Reverse</h1>
<div class='container' id='row-reverse'>
<div class='box'>
<h2>1</h2>
</div>
<div class='box'>
<h2>2</h2>
</div>
<div class='box'>
<h2>3</h2>
</div>
<div class='box'>
<h2>4</h2>
</div>
<div class='box'>
<h2>5</h2>
</div>
</div>
<h1>Flex-Direction: Column</h1>
<div class='container' id='column'>
<div class='box'>
<h2>1</h2>
</div>
<div class='box'>
<h2>2</h2>
</div>
<div class='box'>
<h2>3</h2>
</div>
<div class='box'>
<h2>4</h2>
</div>
<div class='box'>
<h2>5</h2>
</div>
</div>
<h1>Flex-Direction: Column-Reverse</h1>
<div class='container' id='column-reverse'>
<div class='box'>
<h2>1</h2>
</div>
<div class='box'>
<h2>2</h2>
</div>
<div class='box'>
<h2>3</h2>
</div>
<div class='box'>
<h2>4</h2>
</div>
<div class='box'>
<h2>5</h2>
</div>
</div>
</body>
</html>