Layout on the Web: What’s New

Welcome to the MAX web layout lab. We are going to build a a couple different page layouts using the FlexBox and Grid Layout modules, and then experiment with flowing text through them with Regions and Exclusions. Although each exercise is part of a sequence, you can start at any point without completing the previous exercises. If you fall behind, don’t worry, you can always start fresh on the next exercise (or cheat and view the solutions).

Each folder contains an example of the features that will be used, followed by a series of exercises. You should only need to work in the area marked “WORK HERE”.

Getting Started:

  1. Open Chrome Canary

  2. In Chrome Canary, navigate to about://flags

  3. Open up Brackets

  4. In Brackets up the Layout Lab Exercises folder

01 FlexBox Layout

Specification

Children of a container with display: flex can lay out in any direction, wrap, and flexibly grow or shrink their sizes to fit the available space.

FlexBox Example

Open the example file to see how some of the basic FlexBox properties work.

FlexBox Exercise

Goal: Simulate a paged multicolumn layout using FlexBox

  1. Create a FlexBox layout container

    Under the .flexbox selector, add

  2. Set the initial dimensions of the FlexBox children

    Under the .flexbox > * selector, add

  3. Describe how the FlexBox children grow and shrink

  4. Make it responsive

02 Grid Layout

Specification

A container with display: grid creates a grid of fixed or flexibly sized rows and columns. Children can then align and size themselves to the grid. The specification and implementations are still both in flux.

Grid Example

Open the example file to view a basic grid setup with several positioned children.

Grid Exercise

Goal: Create a responsive two column grid layout with an inset

  1. Create a Grid layout container

    Under .grid, add

  2. Position the two columns

    Under .one, .two, add

    Under .one, add

    Under .two, add

  3. Position the inset

    Under .inset, add

  4. Add a simplified reduced-width layout

    Add and (max-width: 600px) to the media query

    Under the media query, add

    .one, .two, .inset

    .one

    .two

    .inset

  5. Remove the debugging CSS

03 Regions

Specification

CSS Regions allow you to flow content through multiple areas called regions.

Regions Example

Open the example to see how content can be placed into a named flow that regions can then pull from.

Regions Exercise 1

Goal: Flow content through your previously created FlexBox layout

  1. Put content into a named flow

    Under .content, add

  2. Pull content from the above named flow

    Under .flexbox > *, add

Regions Exercise 2

Goal: Flow content through your previously created Grid layout

  1. Put content into a named flow

    Under .content, add

  2. Pull content from the above named flow

    Under .one, .two, add

04 Exclusions

Specification

CSS Exclusions allow you to customize the shape content flows inside and around.

Exclusions Example

Open the example to see how content can wrap inside and around a circle.

Exclusions Exercise 1

Goal: Wrap text tightly around the initial ‘A’ drop cap

  1. Use the shape utility with dropcap-a.svg to create a shape-outside

  2. Apply your shape-outside

    Under .content:first-letter, set -webkit-shape-outside to

Exclusions Exercise 2

Goal: Wrap text around the image inset

  1. Use the shape utility with grid-template.svg to create two shape-insides

  2. Apply your shape-insides

    Under .one set -webkit-shape-inside to

    Under .two set -webkit-shape-inside to

  3. Apply the shape-insides only on larger screens

05 Web Components (aka Bonus Round)

Specification

The Web Components Specification contains several different methods of factoring out presentational markup, including a new template element, a presentation-only shadow DOM, and custom, reusable components.

Templates Example

The example demonstrates the use of the the <template> element to dynamically generate repeating content.

Templates Exercise

Goal: Repeat the template to add regions until all the content fits

  1. Note the method of getting named flows

  2. Inside the while loop, add

Shadow DOM Example

Open the example to see how we can apply presentation-only markup via the Shadow DOM. While the Shadow DOM content is rendered, it does not affect the original DOM (fire up the Inspector to be sure).

Shadow DOM Exercise

Goal: Use the Shadow DOM to apply a regions template to the content

  1. Add a Shadow DOM root node to your content

    In the window.onload function, add

  2. Pull the original DOM’s content into the Shadow DOM

    At the end of the <template> tag, add

  3. Place the content into a named flow. Note that you will have to use the distributed pseudo selector

    In the template’s <style> element, add

    content::-webkit-distributed(*)

  4. Pull content from the named flow into the regions

    In the template’s <style> element, add

    .one, .two

06 Results

Check out the results folder to see the solutions for each of the exercises.

FlexBox Template Result

Grid Template Result

Web Components Template Result

Web Components Shadow DOM Result