A Simple Beginners Guide To Flexbox And CSS Grid


In this post, we’ll take a look at two layout systems used in CSS, Flexbox and CSS Grid. We’ll also look at how combining both can help you achieve your project design goals.

Flexbox and CSS Grid are two powerful layout systems in CSS that offer different approaches to creating flexible and responsive web layouts.

Here’s an overview of each system:

Flexbox

Flexbox, short for Flexible Box Layout, is developed for building one-dimensional layouts, typically along a single axis—either horizontally or vertically. It is ideal for arranging items within a container, distributing space, and aligning content.

Let’s take a look at the key features of Flexbox:

  1. One-dimensional layout: Flexbox focuses on arranging items in a row or column.
  2. Flex container and flex items: The parent container becomes a flex container by applying, display: flex and the child items become flex items.
  3. Main and cross axes: Flexbox has a main axis (horizontal or vertical) and a cross axis perpendicular to it.
  4. Flexible sizing: Flex items can grow or shrink to fit available space using properties like flex-grow, flex-shrink, and flex-basis.
  5. Alignment and justification: Flexbox provides properties like justify-content and align-items to control item alignment along the main and cross axes.

OK, so hopefully this will give you a good base insight into Flexbox. Next, we’ll take a look at CSS Grid.

CSS Grid

CSS Grid Layout, often referred to as CSS Grid, is a two-dimensional layout system that allows you to create complex grid-based layouts. It offers precise control over rows, columns, and their placement, enabling flexible and responsive designs.

The key features of CSS Grid include:

  1. Two-dimensional layout: CSS Grid creates a grid of rows and columns, allowing elements to be positioned anywhere in the grid.
  2. Grid container and grid items: The parent container becomes a grid container by applying display: grid, and the child items become grid items.
  3. Explicit grid definition: Grid layout allows you to define the number of rows and columns, their sizes, and their alignment using properties like grid-template-rows, grid-template-columns, and grid-gap.
  4. Grid tracks and cells: Grid tracks are the rows or columns in the grid, and cells are the spaces between them where grid items are placed.
  5. Responsive design: CSS Grid supports responsive layouts by allowing you to define different grid structures for different screen sizes using media queries.

When to use Flexbox or CSS Grid

Here’s the thing to remember –

  • Flexbox is great for simpler one-dimensional layouts, such as navigation menus, flexible content containers, or vertically centering items.
  • CSS Grid is well-suited for complex, two-dimensional layouts, like full-page grids, card-based layouts, or designs with explicit control over rows and columns.

In practice, you can also combine Flexbox and CSS Grid, using Flexbox to control the layout within grid items or using Grid to create flexible sections within a Flexbox container.

If you follow my Bricks Builder Course, you know that we are able to combine the Flexbox model with CSS grid in our website design projects. Especially now that we have CSS grid controls, this still requires you to learn a little bit about CSS grids.

Both Flexbox and CSS Grid are powerful tools, and choosing one or combining them depends on the specific layout requirements and design goals of your project.

Conclusion

Hopefully, you found this short little post useful. Whether you are learning to design websites using Bootstrap or a website builders tool like Bricks or Oxygen with WordPress, understanding the basic fundamentals of layouts is important.

Get full access to all of the content

Everything you need to design your website with WordPress, Oxygen, Bricks Builder, plus over 100 video tutorials, written tutorials, code snippets, and more.

Become a member

FREE WEB DESIGN LESSON

SIGNUP FOR MY FREE 40-MINUTE OXYGEN BUILDER COURSE TASTER