1.0: Intro
CSS Flexbox is a method used to layout a website. Grids are a method used to layout a website. These tools allow developers to separate content and presentation. They give an independence to our content that we didn't have before but we need now, and forever, going forward. You may be asking yourself, "Does one replace the other?" No. Although similar, grids and flexboxes are different. It is best to think about them as complementary methods to structure the layout of a web site.
Flexbox is for one-dimensional layouts - anything that needs to be laid out in a straight line (or in a broken line, which would be a single straight line if they were joined back together). Grid is for two-dimensional layouts. It can be used as a low-powered flexbox substitute (we’re trying to make sure that a single-column/row grid acts very similar to a flexbox), but that’s not using its full power. - Tab Atkins
There is a lot to learn about these two methods, their properties and values. In addition to what you will learn here, there are many excellent resources out there. (Links to these resources provided in glossary)
Horizontal & Vertical AXIS
Flexbox layout distributes space along a SINGLE COLUMN (the cross-axis) OR ROW (the main-axis). Similar to floats but better!
Grid layout divides space into COLUMNS (block or column axis) AND ROWS (inline or row axis). Similar to tables but better!
Flexbox
Grid
In Action
Both tools utilize containers (parents) and items (child).
Let's dive right in and take a look at how flexbox and grid handle the common task of centering an item on a page.
Flexbox
Focus: container with centered item
Property
Value
display
flex
Copy and paste the following code. You should see a white square(item/child) centered inside a blue rectangle(container/parent).
Grid
Focus: container with centered item
PROPERTIES
VALUES
display
grid
grid-template-columns
repeat
grid-template-rows
fr
justify-content
There are probably two(2) terms that you have questions about: fr and em. These are units of measurements like px (pixels) and % (percentage).
absolute lengths: these are fixed and will appear exactly that size (best not to use these for anything other than print in which you know the output medium and size.
cm - centimeters
mm - millimeters
in - inches
px* -pixels(1px = 1/96th of 1in)
pt - points(1pt = 1/72 of 1in)
pc - picas (1pc = 12 pt)
Last updated