Lesson 12 - Flexbox
Lesson 12 - Flexbox
FLEXBOX
Lesson 12
LESSON OBJECTIVES
▪ Flex-start
• This is the initial
value. Flex items are
packed toward the start
of the line.
justify-content values
▪ flex-end
• Flex items are packed
toward the end of the
line.
justify-content values
▪ center
• Flex items are packed
toward the center of
the line
justify-content values
▪ Space-between
• Flex items are evenly
distributed in the
line.
justify-content values
▪ Space-around
• Flex items are evenly
distributed in the
line, with half-size
spaces on either end.
GROUPING FLEX ITEMS
▪ Flex containers only know how to position
elements that are one level deep (i.e., their
child elements).
▪ They don’t care one bit about what’s inside
their flex items.
▪ This means that grouping flex items is another
weapon in your layout-creation arsenal.
▪ Wrapping a bunch of items in an extra <div>
results in a totally different web page.
CROSS-AXIS (VERTICAL) ALIGNMENT
▪ flex-start
• Flex items are packed
toward the cross-start
of the line.
Align-items values
▪ flex-end
• Flex items are packed
toward the cross-end of
the line.
Align-items values
▪ center
• Flex items are packed
toward the center of
the line
Align-items values
▪ baseline
• Flex items are aligned
such that their
baselines align
Align-items values
▪ stretch
• This is the initial
value. The flex items
are stretched out from
the cross-start to the
cross-end
WRAPPING FLEX ITEMS
▪ Flexbox is a more powerful alternative to
float-based grids.
▪ Not only can it render items as a grid—it can
change their alignment, direction, order, and
size, too.
▪ To create a grid, we need the flex-wrap
property.
flex-wrap
▪ wrap-reverse
• Same as wrap, except
the cross-start and
cross-end directions
are swapped
FLEX CONTAINER DIRECTION
▪ “Direction” refers to whether a container
renders its items horizontally or vertically.
▪ So far, all the containers we’ve seen use the
default horizontal direction, which means
items are drawn one after another in the same
row before popping down to the next column
when they run out of space.
Flex-direction
▪ The flex-direction property specifies how flex
items are placed in the flex container, by
setting the direction of the flex container’s
main axis.
▪ This determines the direction that flex items
are laid out in.
▪ The direction of the axes is affected by the
writing mode and directionality of the text
Flex-direction values
▪ row
• This is the initial
value. The flex
container’s main axis
has the same
orientation as the
current writing mode
Flex-direction values
▪ row-reverse
• Same as row, except the
main-start and main-end
directions are swapped.
Flex-direction values
▪ column
• The flex container’s
main axis is rotated so
that the main-start is
at the top and the
main-end is at the
bottom.
Flex-direction values
▪ column-reverse
• Same as column, except
that main-start and
main-end directions are
swapped
FLEX ITEM ORDER
▪ flex-start
• The flex item is packed
toward the cross-start
of the line
Align-self values
▪ flex-end
• The flex item is packed
toward the cross-end of
the line
Align-self values
▪ center
• The flex item’s margin
box is centered in the
cross axis within the
line.
Align-self values
▪ baseline
• The element is
positioned at the
baseline of the
container
Align-self values
▪ stretch
• The element is
positioned to fit the
container
FLEXIBLE ITEMS