Lecture 9
Lecture 9
The element above represents a flex container (the blue area) with three flex items.
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
CSS Flex Container
Parent Element (Container)
Like we specified in the previous, this is a
flex container (the blue area) with three flex items:
The flex container becomes flexible by setting the display property to flex:
.flex-container {
display: flex;
}
The flex-direction Property
The flex-direction property defines in which direction
the container wants to stack the flex items.
.flex-container {
display: flex;
flex-direction: column;
}
The column-reverse value stacks the flex items
vertically (but from bottom to top):
.flex-container {
display: flex;
flex-direction: column-reverse;
}
The row value stacks the flex items horizontally
(from left to right):
.flex-container {
display: flex;
flex-direction: row;
}
The row-reverse value stacks the flex items horizontally (but
from right to left):
.flex-container {
display: flex;
flex-direction: row-reverse;
}
flex-wrap Property
The flex-wrap property specifies whether the flex items
should wrap or not.
The examples below have 12 flex items, to better
demonstrate the flex-wrap property.
The center value aligns the flex items at the center of the container :
.flex-container {
display: flex;
justify-content: center;
}
The flex-start value aligns the flex items at the beginning of the container (this is default):
.flex-container {
display: flex;
justify-content: flex-start;
}
The flex-end value aligns the flex items at the
end of the container:
.flex-container {
display: flex;
justify-content: flex-end;
}
.flex-container {
display: flex;
height: 200px;
align-items: flex-end;
}
The stretch value stretches the flex items to fill the container (this is default):
.flex-container {
display: flex;
height: 200px;
align-items: stretch;
}
The CSS Flexbox Container Properties
Property Description
justify-content Horizontally aligns the flex items when the items do not
use all available space on the main-axis