Web Structure

Web Structure

New

Intro to HTML & CSS

Intro to HTML & CSS

New

3:38

HTML Structure

HTML Structure

New

1:55

The Box Model

The Box Model

New

1:54

Responsive Design

Responsive Design

New

Intro to Responsive Design

Intro to Responsive Design

New

2:21

CSS Layout

CSS Layout

New

Intro to Web Layout

Intro to Web Layout

New

2:27

Intro to Flexbox

Intro to Flexbox

New

2:27

Grid layouts overview

Grid layouts overview

New

4:18

Width & Height Units

Width & Height Units

New

3:59

Positioning Overview

Positioning Overview

New

1:48

Intro to 3D

Intro to 3D

New

2:25

Images & Colors

Images & Colors

New

Image Resolution

Image Resolution

New

3:28

Image File Types (GIF, PNG, SVG, JPEG)

Image File Types (GIF, PNG, SVG, JPEG)

New

2:22

Color values (HEX, RGBA, color names)

Color values (HEX, RGBA, color names)

New

3:22

Dynamic Content

Dynamic Content

New

Intro to Dynamic Content

Intro to Dynamic Content

New

1:36

SEO

SEO

New

Intro to Paid vs. Organic Search

Intro to Paid vs. Organic Search

New

1:34

Intro to 301 Redirects

Intro to 301 Redirects

New

2:39

new course
CSS grid landing page tutorial (36min)

Lesson info

Lesson info

Flexbox (also know as flex or flexible box layout) is a very powerful layout tool that gives you precise alignment and stacking control for all the contents inside an element. It solves many layout problems that designers have been struggling with for a very long time. Here we’ll be covering some of the important concepts you’ll need to understand to master flexbox: 

  • Enabling flex on an element
  • Flex layout settings
  • Flex item settings

We created a flexbox game to help you learn flexbox even faster. Also check out our tutorials for centering elements with flexbox and building equal-height layouts with flexbox.

Explore this project

Want to dig into the project featured in this video and see how everything is put together? We've included the full project we used when making this lesson, and we've shared the link right under this very paragraph.

View and clone this projectDownload lesson assets
Clone this projectDownload project assets

Transcript

Flexbox — which we'll often refer to as "flex", "flexible box layout", or "magic" — is an extremely powerful layout tool which gives us precise control over elements in a box. This lesson is an intro to Flexbox, which is why we've named it Intro to Flexbox. Instead of going step-by-step right through the detailed Flexbox spec, we're going to simply cover the relationship between flex containers (the parents) and flex items (the children).

Let's talk containers. A flex container is the parent element. Flexbox starts when you create a flex container out of something. With this section selected, let's switch our display setting to flex. And that's it. We've created a flex container.

This unlocks all our flex options underneath. If we have multiple items in our flex container, we can choose if we want our layout to be horizontal or vertical. And of course, we have options for justification and alignment of the items inside our container.

We can also reverse the items in our layout, or even wrap these items if their total width exceeds the inner boundary of the container.

But that's the flex container.

Let's talk about the flex items (the children).

Any of the items directly inside (any direct children of the flex container) are referred to as flex items. We can select these and configure layout options which can add to or even override settings we set on the flex container. We can do this on various elements — but keep in mind that in CSS, layout is part of styling. So we can use classes to control how various elements are to behave.

Now something that's really important to note: properties we set on flex containers? They only affect their direct children.

So here, we have a section with a div block inside. Nothing special on our div block. It's just a div block. It's holding some content. And if we select our section (which is serving as the flex container), we can see that we've set our flex layout controls. The div block is being centered. But notice how as we adjust our layout options, the children of the div block remain unaffected.

Now we could select the div block and make it a flex container, too, but the point is that flex containers — in this case the section — the controls we set on flex containers only affect their direct children. Not their children's children.

So. Essentially, Flexbox layouts are achieved between two types of elements: a flex container (the parent element) and a flex item (the child element). You can have many flex items inside your flex container, and you can use a div or any kind of container to nest and group other elements to sort them however you'd like.