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:
Open Chrome Canary
In Chrome Canary, navigate to about://flags
Experimental Web Platform Features
is enabledExperimental Web Platform Features
above, restart your browserOpen up Brackets
In Brackets up the Layout Lab Exercises folder
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.
Open the example file to see how some of the basic FlexBox properties work.
Goal: Simulate a paged multicolumn layout using FlexBox
Create a FlexBox layout container
Under the .flexbox
selector, add
display: -webkit-flex
to mark this block for Flexible Box layout-webkit-flex-wrap: wrap
to wrap children onto the next line if they don’t fitheight: 100%; max-height: 100%
to size the FlexBox to the viewportSet the initial dimensions of the FlexBox children
Under the .flexbox > *
selector, add
width: 350px
(box-sizing: border-box
is already set)padding: 25px
height: 100%
Describe how the FlexBox children grow and shrink
-webkit-flex-grow: 1
-webkit-flex-shrink: 0
Make it responsive
and (min-width: 700px)
to the media query.flexbox > *:first-child { padding: 25px; }
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.
Open the example file to view a basic grid setup with several positioned children.
Goal: Create a responsive two column grid layout with an inset
Create a Grid layout container
Under .grid
, add
display: -webkit-grid
-webkit-grid-columns: 25% 25% 25% 25%
-webkit-grid-rows: 33% 34% 33%
width: 100%
height: 100%
Position the two columns
Under .one, .two
, add
-webkit-grid-row: 1 / -1
Under .one
, add
-webkit-grid-column: 1 / -3
Under .two
, add
-webkit-grid-column: 3 / -1
Position the inset
Under .inset
, add
-webkit-grid-row: 2 / -2
-webkit-grid-column: 2 / -2
Add a simplified reduced-width layout
Add and (max-width: 600px)
to the media query
Under the media query, add
.one, .two, .inset
-webkit-grid-column: 1 / -1
.one
-webkit-grid-row: 1
.two
-webkit-grid-row: 3
height: auto
.inset
-webkit-grid-row: 2
Remove the debugging CSS
CSS Regions allow you to flow content through multiple areas called regions.
Open the example to see how content can be placed into a named flow that regions can then pull from.
Goal: Flow content through your previously created FlexBox layout
Put content into a named flow
Under .content
, add
-webkit-flow-into: story-flow
Pull content from the above named flow
Under .flexbox > *
, add
-webkit-flow-from: story-flow
Goal: Flow content through your previously created Grid layout
Put content into a named flow
Under .content
, add
-webkit-flow-into: story-flow
Pull content from the above named flow
Under .one, .two
, add
-webkit-flow-from: story-flow
CSS Exclusions allow you to customize the shape content flows inside and around.
Open the example to see how content can wrap inside and around a circle.
Goal: Wrap text tightly around the initial ‘A’ drop cap
Use the shape utility with dropcap-a.svg
to create a shape-outside
Apply your shape-outside
Under .content:first-letter
, set -webkit-shape-outside
to
polygon(0 0, 0 100%, 100% 100%, 100% 95%, 85% 85%, 55% 0)
Goal: Wrap text around the image inset
Use the shape utility with grid-template.svg
to create two shape-insides
Apply your shape-insides
Under .one
set -webkit-shape-inside
to
polygon(0 0, 100% 0, 100% 33%, 50% 33%, 50% 67%, 100% 67%, 100% 100%, 0 100%)
Under .two
set -webkit-shape-inside
to
polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 67%, 50% 67%, 50% 33%, 0% 33%)
Apply the shape-insides only on larger screens
and(min-width: 600px)
to the media queryThe 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.
The example demonstrates the use of the the <template>
element to dynamically generate repeating content.
Goal: Repeat the template to add regions until all the content fits
Note the method of getting named flows
Inside the while
loop, add
flexbox.appendChild(template.content.cloneNode(true))
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).
Goal: Use the Shadow DOM to apply a regions template to the content
Add a Shadow DOM root node to your content
In the window.onload
function, add
var template = document.querySelector('template')
var content = document.querySelector('.content')
var shadow = content.webkitCreateShadowRoot()
shadow.appendChild(template.content.cloneNode(true))
template.remove()
Pull the original DOM’s content into the Shadow DOM
At the end of the <template>
tag, add
<content></content>
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(*)
-webkit-flow-into: story
Pull content from the named flow into the regions
In the template’s <style>
element, add
.one, .two
-webkit-flow-from: story
Check out the results folder to see the solutions for each of the exercises.