reading-notes

Todd Wolden

View on GitHub

Course 201 Class Eight “CSS Layout”

CSS Flexbox

The Flexible Box Layout Model (flexbox) is a layout model designed for one-dimensional content. It excels at taking a bunch of items which have different sizes, and returning the best layout for those items.

This is the ideal layout model for this sidebar pattern. Flexbox not only helps lay the sidebar and content out inline, but where there’s not enough space remaining, the sidebar will break onto a new line. Instead of setting rigid dimensions for the browser to follow, with flexbox, you can instead provide flexible boundaries to hint how the content could display.

Flex layouts have the following features, which you will be able to explore in this guide.

The key to understanding flexbox is to understand the concept of a main axis and a cross axis. The main axis is the one set by your flex-direction property. If that is row your main axis is along the row, if it is column your main axis is along the column. Flex items move as a group on the main axis. Remember: we’ve got a bunch of things and we are trying to get the best layout for them as a group. The cross axis runs in the other direction to the main axis, so if flex-direction is row the cross axis runs along the column.

Axis Layout

You can do two things on the cross axis. You can move the items individually or as a group so they align against each other and the flex container. Also, if you have wrapped flex lines, you can treat those lines as a group in order to control how space is assigned to those lines. You will see how this all works in practice throughout this guide, for now just keep in mind that the main axis follows your flex-direction.

Questions

Being one dimensional means that flexbot only deals with columns and rows.

The main axis is either row or column and defines the direction of how your flex items are placed in the container. Cross axis is perpendicular to the main axis.

You can use row-reverse or column-reverse and then the items on page do not match what an html screen reader will show. This can cause accesibility issues.

Why FlexBox

Specifying what elements to lay out as flexible boxes

To start with, we need to select which elements are to be laid out as flexible boxes. To do this, we set a special value of display on the parent element of the elements you want to affect. In this case we want to lay out the <article> elements, so we set this on the <section>:

section {

  display: flex;

}

Flex Flow

Question

Resources

CSS Layout

CSS Flexbox

Return to the Table of Contents

Table of Contents