CSS Layout

Back to menu

flexbox

Page layouts can be easily achieved with the added bonus of equalised heights. To create gutters we can use the same technique with negative margin and added paddings like we did with the float and inline-block layouts.

We can again combine our grid CSS with the width utility classes for easy responsive layouts.

Holy grail layout

header

CSS Layout

The history of CSS Layout on the web is largely web developers using tools for layout which were not intended for layout.

footer

Holy grail layout - different order, same markup

A very useful benefit of flexbox is the order property which can be used to change the display order of items without changing the source order.

This is a common situation in responsive layouts where you might want a certain order on smaller viewports and a different one on larger viewports. Resize to browser to see that the nav element comes after the header on smaller viewports.

header

CSS Layout

The history of CSS Layout on the web is largely web developers using tools for layout which were not intended for layout.

footer

Product grid

This may look like a multi dimensional layout but really its a one dimensional layout with wrapping. If the wrapping was turned off it would all display in one line.

Column spanning is easily achievable but row spanning is not possible.

CSS Pocket Reference

Know your margins from your paddings.

Equal heights :)

CSS Pocket Reference

meow vol iii

Volume 3, now meow's what I call literature

meow vol 3

meow vol iii

Volume 3, now meow's what I call literature

meow vol 3

meow vol iii

Volume 3, now meow's what I call literature

meow vol 3

meow vol iii

Volume 3, now meow's what I call literature

meow vol 3

meow vol iii

Volume 3, now meow's what I call literature

meow vol 3

Justified content

flexbox's justify-content: space-between; can be used to easily distribute items evenly along a line.

You can layout items along a line vertically by using the flex-direction property.

Vertically aligned content

Vertically aligning items is now trivially easy.

Vertically centered text!

Multi dimensional layout

You can create a multi dimensional layout that has both row spanning and col spanning by combining multiple flexbox declarations. In the example below we have three flexbox declarations.

The first is on the <div class="multi-dime"> wrapper element lays the <div class="multi-dime__col"> elements out side by side.

Then flexbox is declared on the two <div class="multi-dime__col"> elements with the property flex-direction: column declared so the elements inside are displayed vertically

The flex-grow property is used on the header and article elements to row span.

header
CSS Layout
article

Article heading

The introduction of flexboox and CSS Grids gives developers great tools for laying out web pages.