Flex Box
Flex Box
By Zahid Javed
Why Flexbox?
Before Flexbox, we were mainly using
floats for layout and for those CSS
developers, we all know the
frustrations and limitations of the old
way -- especially the ability to vertically
center inside a parent. Ugh, that was so
annoying! Not anymore! Flexbox for
the win!
What is Flexbox?
Flexbox is a layout model that allows you to distribute space and align
elements within a container, even when the sizes of the elements are
unknown or dynamic. Unlike traditional layout models, such as floats
and positioning, Flexbox provides a more predictable and maintainable
way to arrange elements in a container, making it ideal for building
complex interfaces.
What is Flexbox?
The main idea behind the flex layout is to give the container the ability
to alter its items’ width/height (and order) to best fill the available
space (mostly to accommodate to all kind of display devices and screen
sizes). A flex container expands items to fill available free space or
shrinks them to prevent overflow.
Basics & Terminology
If “regular” layout is based on both block and inline flow directions, the flex
layout is based on “flex-flow directions”. Please have a look at this figure
from the specification, explaining the main idea behind the flex layout.
Basics & Terminology
Basics & Terminology
HTML Code
CSS Code
Properties for the Parent
Flex Container Properties
display
There are 2 types of flex
container: flex will create a
block level flex container, and
inline-flex will create an inline
level flex container.
Flex Container Properties
display
This defines a flex container; inline or block depending on the given
value. It enables a flex context for all its direct children.
Block vs Inline
Very simply explained, block
element takes up the entire
width of the container. They
look like building blocks
where each block is stacked
on each other. Whereas inline
element only takes up the
space it needs. So they
appear to be in a line, or side
by side of each other
Flex Container Properties
5. align-items: This property aligns flex items along the cross axis. It can
be used to center or align them to the start or end of the container.
https://blog.suprabha.me/61-learn-css-by-playing-games
https://www.youtube.com/watch?v=-DNLYk5uzl8&t=444s
Reference
• https://morioh.com/a/d3da54b5b69c/the-complete-guide-to-css-
flexbox
• https://medium.com/@MakeComputerScienceGreatAgain/understan
ding-flexbox-a-comprehensive-guide-992bcd5f04de
• https://blog.suprabha.me/61-learn-css-by-playing-games
• https://www.turing.com/kb/building-a-smart-layout-using-flexbox
• https://www.samanthaming.com/flexbox30/22-flex-grow-calculation/