Activate Flexbox
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
.container {
display: flex;
}
Flexbox Axis
- Main Axis: This is where your elements will primarily align themselves. (Think horizontal rows by default)
- Cross Axis: This is the secondary direction, which is at 90 degrees to the main axis. (Think vertical columns by default)
Flex Direction: Changing the Flow
.container {
display: flex;
flex-direction: column;
}
Justify Content: Controlling the Main Axis
.container {
display: flex;
justify-content: flex-start;
}
Align Items: Controlling the Cross Axis
.container {
display: flex;
align-items: stretch;
}
The Gap Property
.container {
display: flex;
gap: 30px;
}
Flex Wrap: Avoiding the Crush