Introduction to CSS Grid Layout

Rachel Andrew
Rachel AndrewWriter, speaker, co-founder of Perch CMS. Google Developer Expert for Web Technologies at A List Apart
Introduction to CSS
Grid Layout
Rachel Andrew
Fluent, April 2015
Rachel Andrew
http://rachelandrew.co.uk
@rachelandrew
http://grabaperch.com
CSS in 2015 is amazing.
The trouble with CSS layout
• Floats and clearfix hacks
• Absolute positioning means elements are taken
out of document flow and risk overlaps
• Redundant markup and positioning oddities with
display: table
• White space issues with inline-block
https://www.flickr.com/photos/zervas/2810241612
Flexbox?
Seeing Flexbox as the silver bullet for
layout issues is likely to lead us down
another path of layout hacks.
The cost of taming layout methods
• Developer hours spent learning non-obvious
concepts.
• Compromises in terms of document semantics in
order to achieve responsive layouts.
• Needing to lean on frameworks to help with
complex math.
• Adding markup to create grids
• Using preprocessors to abstract layout hacks
We need a designed for purpose
layout system for the sites and
applications we develop today.
CSS Grid Layout
Our HTML consists of a
div with a class of
wrapper and six child
elements.
<div class="wrapper">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
<div class="d">D</div>
<div class="e">E</div>
<div class="f">F</div>
</div>
To create a grid we use a
new value of the display
property.
display: grid
.wrapper {
display: grid;
}
We describe the grid using
the new properties:
grid-template-columns
grid-template-rows
.wrapper {
display: grid;
grid-template-columns:
100px 10px 100px 10px 100px;
grid-template-rows:
auto 10px auto;
}
We position items using the
new properties:
grid-column-start

grid-column-end

grid-row-start

grid-row-end
.a {
grid-column-start: 1;
grid-column-end: 2;
grid-row-start: 1;
grid-row-end: 2;
}
To position an item bottom
centre, I start at column
line 3, this is the line after
the gutter track.
.b {
grid-column-start: 3;
grid-column-end: 4;
grid-row-start: 3;
grid-row-end: 4;
}
To span more tracks we
just change the end row or
column line.
.b {
grid-column-start: 3;
grid-column-end: 6;
grid-row-start: 3;
grid-row-end: 4;
}
The longhand for line-
based placement means
up to 4 properties to
position each element. .a {
grid-column-start: 1;
grid-column-end: 2;
grid-row-start: 1;
grid-row-end: 2;
}
.b {
grid-column-start: 3;
grid-column-end: 4;
grid-row-start: 3;
grid-row-end: 4;
}
Declare start and end
values with grid-column
and grid-row.
Values are separated by a
/ symbol.
.a {
grid-column: 1 / 2;
grid-row: 1 / 2;
}
.b {
grid-column: 3 / 6;
grid-row: 3 / 4;
}
Declare all 4 values using
the grid-area property.
.a {
grid-area: 1 / 1 / 2 / 2;
}
.b {
grid-area: 3 / 3 / 4 / 6;
}
Grid Terminology
Grid Lines
Lines can be horizontal or vertical. They
are referred to by number and can be
named.
Highlighted is Column Line 2.
Grid Track
A Grid Track is the space between two
Grid Lines. Tracks can be horizontal or
vertical (rows or columns).
The highlighted Grid Track is between
Row Lines 2 and 3.
Grid Cell
The smallest unit on our grid, a Grid Cell
is the space between four Grid Lines. It’s
just like a table cell.
The highlighted Grid Cell is between row
lines 2 and 3 and column lines 2 and 3.
Grid Area
Any area of the Grid bound by 4 Grid
Lines. It can contain many Grid Cells.
The highlighted Grid Area is between
row lines 1 and 3, column lines 2 and 4.
All examples can be found at http://gridbyexample.com. Use Chrome. Enable “Experimental Web Platform Features” flag.
Line-based placement
http://gridbyexample.com/examples/code/layout9.html
The HTML around my
page content.
The various areas of my
page are child elements
of a div with a class of
wrapper.
<div class="wrapper">
<header class="mainheader"></header>
<div class="panel"></div>
<div class="content"></div>
</div>
Introduction to CSS Grid Layout
Declaring a grid on
wrapper.
The grid has three
columns, and four rows.
.wrapper {
width: 100%;
max-width: 960px;
margin: 0 auto;
display: grid;
grid-template-columns: 30% 5% 65%;
grid-template-rows: 40px auto 20px auto;
}
Introduction to CSS Grid Layout
Positioning our elements
using the grid-column and
grid-row shorthand.
This is all we need to do
to create our layout.
.mainheader {
grid-column: 1 / 4;
grid-row: 2 / 3;
}
.panel {
grid-column: 1 / 2;
grid-row: 4 / 5;
}
.content {
grid-column: 3 / 4;
grid-row: 4 / 5;
}
Introduction to CSS Grid Layout
Introduction to CSS Grid Layout
I can add a footer to this
layout - and it doesn’t
matter in which unusual
place I want to add the
markup.
<div class="wrapper">
<header class="mainheader"></header>
<footer class="mainfooter"></footer>
<div class="panel"></div>
<div class="content"></div>
</div>
Positioning the footer
between row lines five
and six.
.mainfooter {
grid-column: 1 / 4;
grid-row: 5 / 6;
}
Introduction to CSS Grid Layout
Our grid only has 5 row
lines specified - yet we
placed an item between
row lines 5 and 6.
Grid creates an implicit
grid line for us.
.wrapper {
display: grid;
grid-template-columns: 30% 5% 65%;
grid-template-rows: 40px auto 20px auto;
}
.mainfooter {
grid-column: 1 / 4;
grid-row: 5 / 6;
}
Grid lines can be explicit or implicit
• Explicit grid lines are those that you specify and
give sizing information.

• Implicit lines are created when you place
something into a row or column you have not
specified with grid-template-rows or grid-
template-columns
Grid is “table like” however …
• Unlike a table for layout Grid does not rely on
your content being a particular order in the
source.

• Being entirely described in CSS we can move
things around the Grid at different breakpoints,
introduce or redefine a Grid for any breakpoint.
Using Grid to order the
page elements in a single
column for narrow screen
widths.
.wrapper {
display: grid;
grid-template-rows:
10px auto 10px auto 10px auto 10px auto;
}
.mainheader {
grid-row: 2 / 3;
}
.content {
grid-row: 4 / 5;
}
.panel {
grid-row: 6 / 7;
}
.mainfooter {
grid-row: 8 / 9;
}
Introduction to CSS Grid Layout
Redefine the Grid at min-
width 550 pixels.
Position items as in the
earlier example.
@media (min-width: 550px) {
.wrapper {
grid-template-columns: 30% 5% 65%;
grid-template-rows: 40px auto 20px auto 20px auto;
}
.mainheader {
grid-column: 1 / 4;
grid-row: 2 / 3;
}
.panel {
grid-column: 1 / 2;
grid-row: 4 / 5;
}
.content {
grid-column: 3 / 4;
grid-row: 4 / 5;
}
.mainfooter {
grid-column: 1 / 4;
grid-row: 6 / 7;
}
}
Named Grid Lines
http://gridbyexample.com/examples/code/layout10.html
Name lines with the name
in parenthesis.
Remember we name grid
lines and not grid tracks.
.wrapper {
display: grid;
grid-template-rows:
10px (row-header-start) auto (row-header-end)
10px (row-content-start) auto (row-content-end)
10px (row-panel-start) auto (row-panel-end)
10px (row-footer-start) auto (row-footer-end);
}
Here we are positioning
based on line numbers.
.mainheader {
grid-row: 2 / 3;
}
.content {
grid-row: 4 / 5;
}
.panel {
grid-row: 6 / 7;
}
.mainfooter {
grid-row: 8 / 9;
}
Here we are positioning
by named lines.
.mainheader {
grid-row: row-header-start / row-header-end ;
}
.content {
grid-row: row-content-start / row-content-end;
}
.panel {
grid-row: row-panel-start / row-panel-end ;
}
.mainfooter {
grid-row: row-footer-start / row-footer-end;
}
Grid Template Areas
http://gridbyexample.com/examples/code/layout11.html
We assign a name to the
elements on our page.
I am doing this outside of
any Media Queries.
.mainheader {
grid-area: header;
}
.content {
grid-area: content;
}
.panel {
grid-area: sidebar;
}
.mainfooter {
grid-area: footer;
}
Describe the layout on
the parent element using
the grid-template-areas
property.
A period “.” indicates that
this grid cell is empty.
.wrapper {
display: grid;
grid-template-rows:
10px auto 10px auto 10px auto 10px auto;
grid-template-areas:
"."
"header"
"."
"content"
"."
"sidebar"
"."
"footer";
}
Introduction to CSS Grid Layout
Introduction to CSS Grid Layout
Redefining the template
areas for the wider
layout. @media (min-width: 550px) {
.wrapper {
grid-template-columns: 30% 5% 65%;
grid-template-rows:
2em auto 1em auto 1em auto;
grid-template-areas:
". . ."
"header header header"
". . ."
"sidebar . content"
". . ."
"footer footer footer"
}
}
Introduction to CSS Grid Layout
Introduction to CSS Grid Layout
A 12 column, flexible grid
getskeleton.com
You can use the repeat
keyword to repeat all or
part of the grid definition.
This would create 4 200
pixel wide tracks,
separated by a 20 pixel
wide gutter track.
grid-template-columns: repeat(4, 200px 20px);
The fr unit is a flexible
length that represents a
fraction of the available
space in the grid
container.
grid-template-columns: 5fr 1fr 10fr 1fr 5fr;
We can give multiple grid
lines the same name.
This means we can use
the span keyword to span
n number of lines, rather
than specifying a specific
grid line.
.wrapper {
grid-template-columns:
repeat(4, (col) 200px (gutter) 20px);
}
.content {
grid-column: col 2 / span gutter 2;
}
The markup used to
create the Grid using the
Skeleton framework.
Like the Bootstrap Grid
and other similar
frameworks it requires
classes that describe the
grid to be added to the
markup.
<div class="container">
<h1>Skeleton Grid</h1>
<div class="example-grid">
<div class="row">
<div class="four columns">Four columns</div>
<div class="four columns">Four columns</div>
<div class="four columns">Four columns</div>
</div>
<div class="row">
<div class="eight columns">Eight columns</div>
<div class="four columns">Four columns</div>
</div>
<div class="row">
<div class="three columns">Three columns</div>
<div class="three columns">Three columns</div>
<div class="three columns">Three columns</div>
<div class="three columns">Three columns</div>
</div>
<div class="row">
<div class="six columns">Six columns</div>
<div class="six columns">Six columns</div>
</div>
</div>
Introduction to CSS Grid Layout
When using CSS Grid
Layout we have no need
to describe our grid in
markup.
<div class="wrapper skeleton">
<h1 class="header">CSS Grid Layout Version</h1>
<div class="box1">Four columns</div>
<div class="box2">Four columns</div>
<div class="box3">Four columns</div>
<div class="box4">Eight columns</div>
<div class="box5">Four columns</div>
<div class="box6">Three columns</div>
<div class="box7">Three columns</div>
<div class="box8">Three columns</div>
<div class="box9">Three columns</div>
<div class="box10">Six columns</div>
<div class="box11">Six columns</div>
</div>
Defining the 12 column
grid.
The repeat keyword
repeats the pattern of
columns or rows the
number of times specified
before the comma.
.wrapper {
display: grid;
grid-template-columns:
repeat(11, (col) 4fr (gutter) 3.5fr ) (col) 4fr (gutter);
grid-template-rows:
auto repeat(4, (row) auto (gutter) 15px);
}
Placing box1 on the grid.
Multiple lines have the
same name. This means we
can use the span keyword.
Here I place box1 starting
at the first line named col,
spanning to the 4th line
named gutter.
In the first row named row,
spanning to the first line
named gutter.
.box1 {
grid-column: col / span gutter 4;
grid-row: row / span gutter;
}
Placing box8 on the grid.
Starting on column line 7,
spanning 3 gutter lines.
In the 3rd row named row,
spanning 1 gutter line.
.box8 {
grid-column: col 7 / span gutter 3;
grid-row: row 3 / span gutter;
}
Introduction to CSS Grid Layout
With Grid Layout we can
easily span rows just like
columns.
.box1b {
grid-column: col / span gutter 4;
grid-row: row / span gutter 2;
}
.box2b {
grid-column: col 5 / span gutter 4;
grid-row: row / span gutter 3;
}
http://gridbyexample.com/examples/code/layout12.html
Browser Support
All my examples work in Chrome and Opera unprefixed - you need
to enable the Experimental Web Platform Features flag.
You can also use Webkit nightlies, with the -webkit prefix.
The work in Blink and Webkit is being done by Igalia, sponsored by
Bloomberg.
IE10 and up has support for the old syntax, with an -ms prefix.
Mozilla are currently implementing Grid in Firefox.
There is a Polyfill under active development: https://github.com/
FremyCompany/css-grid-polyfill/
gridbyexample.com
Thank you!
Slides, links to examples and resources:

http://rachelandrew.co.uk/presentations/css-grid
Office Hours Today - 1.30pm Community Lounge.
@rachelandrew
me@rachelandrew.co.uk
1 of 73

Recommended

CSS Grid by
CSS GridCSS Grid
CSS GridDigital Surgeons
2.8K views33 slides
Introducing CSS Grid by
Introducing CSS GridIntroducing CSS Grid
Introducing CSS GridJason Yingling
2.5K views27 slides
Flexbox and Grid Layout by
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid LayoutRachel Andrew
7K views98 slides
World of CSS Grid by
World of CSS GridWorld of CSS Grid
World of CSS GridElad Shechter
958 views40 slides
CSS Day: CSS Grid Layout by
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout Rachel Andrew
9.6K views122 slides
Introducing CSS Grid Layout by
Introducing CSS Grid LayoutIntroducing CSS Grid Layout
Introducing CSS Grid LayoutRachel Andrew
4.8K views143 slides

More Related Content

What's hot

Html forms by
Html formsHtml forms
Html formsEr. Nawaraj Bhandari
362 views35 slides
CSS by
CSSCSS
CSSVladimir Zhidal
1.7K views150 slides
Introduction to flexbox by
Introduction  to  flexboxIntroduction  to  flexbox
Introduction to flexboxJyoti Gautam
135 views14 slides
Media queries A to Z by
Media queries A to ZMedia queries A to Z
Media queries A to ZShameem Reza
853 views17 slides
Css3 by
Css3Css3
Css3Deepak Mangal
4.2K views18 slides
CSS Selectors by
CSS SelectorsCSS Selectors
CSS SelectorsRachel Andrew
4K views121 slides

What's hot(20)

Introduction to flexbox by Jyoti Gautam
Introduction  to  flexboxIntroduction  to  flexbox
Introduction to flexbox
Jyoti Gautam135 views
Media queries A to Z by Shameem Reza
Media queries A to ZMedia queries A to Z
Media queries A to Z
Shameem Reza853 views
Beginners css tutorial for web designers by Singsys Pte Ltd
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
Singsys Pte Ltd3.2K views
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017 by Morten Rand-Hendriksen
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
Introduction to Cascading Style Sheets (CSS) by Chris Poteet
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
Chris Poteet11.7K views
Introduction to HTML by Ajay Khatri
Introduction to HTMLIntroduction to HTML
Introduction to HTML
Ajay Khatri416 views
CSS Layouting #3 : Box Model by Sandhika Galih
CSS Layouting #3 : Box ModelCSS Layouting #3 : Box Model
CSS Layouting #3 : Box Model
Sandhika Galih20.3K views
An Overview of HTML, CSS & Java Script by Fahim Abdullah
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
Fahim Abdullah11.4K views
Introduction to CSS3 by Doris Chen
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
Doris Chen4.4K views
Bootstrap Part - 1 by EPAM Systems
Bootstrap Part - 1Bootstrap Part - 1
Bootstrap Part - 1
EPAM Systems3.6K views

Viewers also liked

Laracon Online: Grid and Flexbox by
Laracon Online: Grid and FlexboxLaracon Online: Grid and Flexbox
Laracon Online: Grid and FlexboxRachel Andrew
1.9K views86 slides
OpenID and decentralised social networks by
OpenID and decentralised social networksOpenID and decentralised social networks
OpenID and decentralised social networksSimon Willison
1.8K views122 slides
Something from Nothing: Simple Ways to Look Sharp When Time is Short by
Something from Nothing: Simple Ways to Look Sharp When Time is ShortSomething from Nothing: Simple Ways to Look Sharp When Time is Short
Something from Nothing: Simple Ways to Look Sharp When Time is Shortkenwtw
1.1K views35 slides
Code driven development: using Features effectively in Drupal 6 and 7 by
Code driven development: using Features effectively in Drupal 6 and 7Code driven development: using Features effectively in Drupal 6 and 7
Code driven development: using Features effectively in Drupal 6 and 7Nuvole
7.2K views55 slides
CSS Grid Systems by
CSS Grid SystemsCSS Grid Systems
CSS Grid SystemsLeonardo Ortega
1.1K views32 slides
An Event Apart SF: CSS Grid Layout by
An Event Apart SF: CSS Grid LayoutAn Event Apart SF: CSS Grid Layout
An Event Apart SF: CSS Grid LayoutRachel Andrew
1.6K views137 slides

Viewers also liked(17)

Laracon Online: Grid and Flexbox by Rachel Andrew
Laracon Online: Grid and FlexboxLaracon Online: Grid and Flexbox
Laracon Online: Grid and Flexbox
Rachel Andrew1.9K views
OpenID and decentralised social networks by Simon Willison
OpenID and decentralised social networksOpenID and decentralised social networks
OpenID and decentralised social networks
Simon Willison1.8K views
Something from Nothing: Simple Ways to Look Sharp When Time is Short by kenwtw
Something from Nothing: Simple Ways to Look Sharp When Time is ShortSomething from Nothing: Simple Ways to Look Sharp When Time is Short
Something from Nothing: Simple Ways to Look Sharp When Time is Short
kenwtw1.1K views
Code driven development: using Features effectively in Drupal 6 and 7 by Nuvole
Code driven development: using Features effectively in Drupal 6 and 7Code driven development: using Features effectively in Drupal 6 and 7
Code driven development: using Features effectively in Drupal 6 and 7
Nuvole7.2K views
An Event Apart SF: CSS Grid Layout by Rachel Andrew
An Event Apart SF: CSS Grid LayoutAn Event Apart SF: CSS Grid Layout
An Event Apart SF: CSS Grid Layout
Rachel Andrew1.6K views
An Event Apart Nashville: CSS Grid Layout by Rachel Andrew
An Event Apart Nashville: CSS Grid LayoutAn Event Apart Nashville: CSS Grid Layout
An Event Apart Nashville: CSS Grid Layout
Rachel Andrew1.7K views
Flexbox and Grid Layout by Rachel Andrew
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid Layout
Rachel Andrew2.6K views
CSS Grid Layout - An Event Apart Orlando by Rachel Andrew
CSS Grid Layout - An Event Apart OrlandoCSS Grid Layout - An Event Apart Orlando
CSS Grid Layout - An Event Apart Orlando
Rachel Andrew958 views
CSS Grid Layout for Frontend NE by Rachel Andrew
CSS Grid Layout for Frontend NECSS Grid Layout for Frontend NE
CSS Grid Layout for Frontend NE
Rachel Andrew2.8K views
CSS Grid Layout - All Things Open by Rachel Andrew
CSS Grid Layout - All Things OpenCSS Grid Layout - All Things Open
CSS Grid Layout - All Things Open
Rachel Andrew1.9K views
Talk Web Design: Get Ready For CSS Grid Layout by Rachel Andrew
Talk Web Design: Get Ready For CSS Grid LayoutTalk Web Design: Get Ready For CSS Grid Layout
Talk Web Design: Get Ready For CSS Grid Layout
Rachel Andrew4.9K views
Grid Systems by Bas Leurs
Grid SystemsGrid Systems
Grid Systems
Bas Leurs282.6K views
Rockin Responsive Content with Panels Layouts by Matt Glaman
Rockin Responsive Content with Panels LayoutsRockin Responsive Content with Panels Layouts
Rockin Responsive Content with Panels Layouts
Matt Glaman6.4K views
CSS Grid Layout by Rachel Andrew
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
Rachel Andrew128.2K views
CSS Grid Layout for Topconf, Linz by Rachel Andrew
CSS Grid Layout for Topconf, LinzCSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, Linz
Rachel Andrew185K views

Similar to Introduction to CSS Grid Layout

Devoxx Belgium: CSS Grid Layout by
Devoxx Belgium: CSS Grid LayoutDevoxx Belgium: CSS Grid Layout
Devoxx Belgium: CSS Grid LayoutRachel Andrew
1.2K views137 slides
CSS Grid Layout by
CSS Grid LayoutCSS Grid Layout
CSS Grid LayoutAll Things Open
679 views137 slides
DevFest Nantes - Start Using CSS Grid Layout today by
DevFest Nantes - Start Using CSS Grid Layout todayDevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout todayRachel Andrew
1.1K views114 slides
What I discovered about layout vis CSS Grid by
What I discovered about layout vis CSS GridWhat I discovered about layout vis CSS Grid
What I discovered about layout vis CSS GridRachel Andrew
9.5K views92 slides
Making the most of New CSS Layout by
Making the most of New CSS LayoutMaking the most of New CSS Layout
Making the most of New CSS LayoutRachel Andrew
1.3K views105 slides
Laying out the future with grid & flexbox - Smashing Conf Freiburg by
Laying out the future with grid & flexbox - Smashing Conf FreiburgLaying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf FreiburgRachel Andrew
2.4K views112 slides

Similar to Introduction to CSS Grid Layout(20)

Devoxx Belgium: CSS Grid Layout by Rachel Andrew
Devoxx Belgium: CSS Grid LayoutDevoxx Belgium: CSS Grid Layout
Devoxx Belgium: CSS Grid Layout
Rachel Andrew1.2K views
DevFest Nantes - Start Using CSS Grid Layout today by Rachel Andrew
DevFest Nantes - Start Using CSS Grid Layout todayDevFest Nantes - Start Using CSS Grid Layout today
DevFest Nantes - Start Using CSS Grid Layout today
Rachel Andrew1.1K views
What I discovered about layout vis CSS Grid by Rachel Andrew
What I discovered about layout vis CSS GridWhat I discovered about layout vis CSS Grid
What I discovered about layout vis CSS Grid
Rachel Andrew9.5K views
Making the most of New CSS Layout by Rachel Andrew
Making the most of New CSS LayoutMaking the most of New CSS Layout
Making the most of New CSS Layout
Rachel Andrew1.3K views
Laying out the future with grid & flexbox - Smashing Conf Freiburg by Rachel Andrew
Laying out the future with grid & flexbox - Smashing Conf FreiburgLaying out the future with grid & flexbox - Smashing Conf Freiburg
Laying out the future with grid & flexbox - Smashing Conf Freiburg
Rachel Andrew2.4K views
Start Using CSS Grid Layout Today - RuhrJS by Rachel Andrew
Start Using CSS Grid Layout Today - RuhrJSStart Using CSS Grid Layout Today - RuhrJS
Start Using CSS Grid Layout Today - RuhrJS
Rachel Andrew990 views
CSSConf.asia - Laying out the future by Rachel Andrew
CSSConf.asia - Laying out the futureCSSConf.asia - Laying out the future
CSSConf.asia - Laying out the future
Rachel Andrew1.3K views
Frontend United: Start using CSS Grid Layout today! by Rachel Andrew
Frontend United: Start using CSS Grid Layout today!Frontend United: Start using CSS Grid Layout today!
Frontend United: Start using CSS Grid Layout today!
Rachel Andrew2.2K views
Evergreen websites for Evergreen browsers by Rachel Andrew
Evergreen websites for Evergreen browsersEvergreen websites for Evergreen browsers
Evergreen websites for Evergreen browsers
Rachel Andrew1.5K views
Grid and Flexbox - Smashing Conf SF by Rachel Andrew
Grid and Flexbox - Smashing Conf SFGrid and Flexbox - Smashing Conf SF
Grid and Flexbox - Smashing Conf SF
Rachel Andrew3.1K views
AEA Chicago CSS Grid Layout by Rachel Andrew
AEA Chicago CSS Grid LayoutAEA Chicago CSS Grid Layout
AEA Chicago CSS Grid Layout
Rachel Andrew1.6K views
CSS Grid Layout: An Event Apart Boston 2016 by Rachel Andrew
CSS Grid Layout: An Event Apart Boston 2016CSS Grid Layout: An Event Apart Boston 2016
CSS Grid Layout: An Event Apart Boston 2016
Rachel Andrew2.9K views
Render Conf: Start using CSS Grid Layout Today by Rachel Andrew
Render Conf: Start using CSS Grid Layout TodayRender Conf: Start using CSS Grid Layout Today
Render Conf: Start using CSS Grid Layout Today
Rachel Andrew3.6K views
Unlocking the Power of CSS Grid Layout by Rachel Andrew
Unlocking the Power of CSS Grid LayoutUnlocking the Power of CSS Grid Layout
Unlocking the Power of CSS Grid Layout
Rachel Andrew2K views
Confoo: The New CSS Layout by Rachel Andrew
Confoo: The New CSS LayoutConfoo: The New CSS Layout
Confoo: The New CSS Layout
Rachel Andrew1.2K views
404.ie: Solving Layout Problems with CSS Grid & Friends by Rachel Andrew
404.ie: Solving Layout Problems with CSS Grid & Friends404.ie: Solving Layout Problems with CSS Grid & Friends
404.ie: Solving Layout Problems with CSS Grid & Friends
Rachel Andrew909 views

More from Rachel Andrew

All Day Hey! Unlocking The Power of CSS Grid Layout by
All Day Hey! Unlocking The Power of CSS Grid LayoutAll Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid LayoutRachel Andrew
2.2K views113 slides
SmashingConf SF: Unlocking the Power of CSS Grid Layout by
SmashingConf SF: Unlocking the Power of CSS Grid LayoutSmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid LayoutRachel Andrew
2.3K views113 slides
The Creative New World of CSS by
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSSRachel Andrew
2K views144 slides
Into the Weeds of CSS Layout by
Into the Weeds of CSS LayoutInto the Weeds of CSS Layout
Into the Weeds of CSS LayoutRachel Andrew
1.5K views93 slides
Solving Layout Problems with CSS Grid & Friends - DevFest17 by
Solving Layout Problems with CSS Grid & Friends - DevFest17Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17Rachel Andrew
2.1K views96 slides
Graduating to Grid by
Graduating to GridGraduating to Grid
Graduating to GridRachel Andrew
1.6K views143 slides

More from Rachel Andrew(16)

All Day Hey! Unlocking The Power of CSS Grid Layout by Rachel Andrew
All Day Hey! Unlocking The Power of CSS Grid LayoutAll Day Hey! Unlocking The Power of CSS Grid Layout
All Day Hey! Unlocking The Power of CSS Grid Layout
Rachel Andrew2.2K views
SmashingConf SF: Unlocking the Power of CSS Grid Layout by Rachel Andrew
SmashingConf SF: Unlocking the Power of CSS Grid LayoutSmashingConf SF: Unlocking the Power of CSS Grid Layout
SmashingConf SF: Unlocking the Power of CSS Grid Layout
Rachel Andrew2.3K views
The Creative New World of CSS by Rachel Andrew
The Creative New World of CSSThe Creative New World of CSS
The Creative New World of CSS
Rachel Andrew2K views
Into the Weeds of CSS Layout by Rachel Andrew
Into the Weeds of CSS LayoutInto the Weeds of CSS Layout
Into the Weeds of CSS Layout
Rachel Andrew1.5K views
Solving Layout Problems with CSS Grid & Friends - DevFest17 by Rachel Andrew
Solving Layout Problems with CSS Grid & Friends - DevFest17Solving Layout Problems with CSS Grid & Friends - DevFest17
Solving Layout Problems with CSS Grid & Friends - DevFest17
Rachel Andrew2.1K views
View Source London: Solving Layout Problems with CSS Grid & Friends by Rachel Andrew
View Source London: Solving Layout Problems with CSS Grid & FriendsView Source London: Solving Layout Problems with CSS Grid & Friends
View Source London: Solving Layout Problems with CSS Grid & Friends
Rachel Andrew1K views
Solving Layout Problems with CSS Grid & Friends - WEBU17 by Rachel Andrew
Solving Layout Problems with CSS Grid & Friends - WEBU17Solving Layout Problems with CSS Grid & Friends - WEBU17
Solving Layout Problems with CSS Grid & Friends - WEBU17
Rachel Andrew902 views
Solving Layout Problems with CSS Grid & Friends - NordicJS by Rachel Andrew
Solving Layout Problems with CSS Grid & Friends - NordicJSSolving Layout Problems with CSS Grid & Friends - NordicJS
Solving Layout Problems with CSS Grid & Friends - NordicJS
Rachel Andrew2.7K views
Google Developers Experts Summit 2017 - CSS Layout by Rachel Andrew
Google Developers Experts Summit 2017 - CSS Layout Google Developers Experts Summit 2017 - CSS Layout
Google Developers Experts Summit 2017 - CSS Layout
Rachel Andrew1.4K views
Web Summer Camp Keynote by Rachel Andrew
Web Summer Camp KeynoteWeb Summer Camp Keynote
Web Summer Camp Keynote
Rachel Andrew1.9K views
New CSS Layout Meets the Real World by Rachel Andrew
New CSS Layout Meets the Real WorldNew CSS Layout Meets the Real World
New CSS Layout Meets the Real World
Rachel Andrew864 views
An Event Apart DC - New CSS Layout meets the Real World by Rachel Andrew
An Event Apart DC - New CSS Layout meets the Real WorldAn Event Apart DC - New CSS Layout meets the Real World
An Event Apart DC - New CSS Layout meets the Real World
Rachel Andrew408 views
Perch, Patterns and Old Browsers by Rachel Andrew
Perch, Patterns and Old BrowsersPerch, Patterns and Old Browsers
Perch, Patterns and Old Browsers
Rachel Andrew1.8K views
Where does CSS come from? by Rachel Andrew
Where does CSS come from?Where does CSS come from?
Where does CSS come from?
Rachel Andrew2.8K views
An Event Apart Seattle - New CSS Layout Meets the Real World by Rachel Andrew
An Event Apart Seattle - New CSS Layout Meets the Real WorldAn Event Apart Seattle - New CSS Layout Meets the Real World
An Event Apart Seattle - New CSS Layout Meets the Real World
Rachel Andrew566 views

Recently uploaded

Microsoft Power Platform.pptx by
Microsoft Power Platform.pptxMicrosoft Power Platform.pptx
Microsoft Power Platform.pptxUni Systems S.M.S.A.
61 views38 slides
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...Bernd Ruecker
48 views69 slides
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... by
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...ShapeBlue
37 views15 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
45 views73 slides
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
115 views25 slides
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...ShapeBlue
61 views15 slides

Recently uploaded(20)

iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker48 views
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... by ShapeBlue
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
ShapeBlue37 views
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... by ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue61 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue44 views
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T by ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue38 views
DRBD Deep Dive - Philipp Reisner - LINBIT by ShapeBlue
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBIT
ShapeBlue44 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue75 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc72 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue64 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray1042 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue89 views
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by ShapeBlue
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
ShapeBlue28 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue60 views
State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue106 views

Introduction to CSS Grid Layout

  • 1. Introduction to CSS Grid Layout Rachel Andrew Fluent, April 2015
  • 3. CSS in 2015 is amazing.
  • 4. The trouble with CSS layout • Floats and clearfix hacks • Absolute positioning means elements are taken out of document flow and risk overlaps • Redundant markup and positioning oddities with display: table • White space issues with inline-block
  • 6. Seeing Flexbox as the silver bullet for layout issues is likely to lead us down another path of layout hacks.
  • 7. The cost of taming layout methods • Developer hours spent learning non-obvious concepts. • Compromises in terms of document semantics in order to achieve responsive layouts. • Needing to lean on frameworks to help with complex math. • Adding markup to create grids • Using preprocessors to abstract layout hacks
  • 8. We need a designed for purpose layout system for the sites and applications we develop today.
  • 10. Our HTML consists of a div with a class of wrapper and six child elements. <div class="wrapper"> <div class="a">A</div> <div class="b">B</div> <div class="c">C</div> <div class="d">D</div> <div class="e">E</div> <div class="f">F</div> </div>
  • 11. To create a grid we use a new value of the display property. display: grid .wrapper { display: grid; }
  • 12. We describe the grid using the new properties: grid-template-columns grid-template-rows .wrapper { display: grid; grid-template-columns: 100px 10px 100px 10px 100px; grid-template-rows: auto 10px auto; }
  • 13. We position items using the new properties: grid-column-start
 grid-column-end
 grid-row-start
 grid-row-end .a { grid-column-start: 1; grid-column-end: 2; grid-row-start: 1; grid-row-end: 2; }
  • 14. To position an item bottom centre, I start at column line 3, this is the line after the gutter track. .b { grid-column-start: 3; grid-column-end: 4; grid-row-start: 3; grid-row-end: 4; }
  • 15. To span more tracks we just change the end row or column line. .b { grid-column-start: 3; grid-column-end: 6; grid-row-start: 3; grid-row-end: 4; }
  • 16. The longhand for line- based placement means up to 4 properties to position each element. .a { grid-column-start: 1; grid-column-end: 2; grid-row-start: 1; grid-row-end: 2; } .b { grid-column-start: 3; grid-column-end: 4; grid-row-start: 3; grid-row-end: 4; }
  • 17. Declare start and end values with grid-column and grid-row. Values are separated by a / symbol. .a { grid-column: 1 / 2; grid-row: 1 / 2; } .b { grid-column: 3 / 6; grid-row: 3 / 4; }
  • 18. Declare all 4 values using the grid-area property. .a { grid-area: 1 / 1 / 2 / 2; } .b { grid-area: 3 / 3 / 4 / 6; }
  • 20. Grid Lines Lines can be horizontal or vertical. They are referred to by number and can be named. Highlighted is Column Line 2.
  • 21. Grid Track A Grid Track is the space between two Grid Lines. Tracks can be horizontal or vertical (rows or columns). The highlighted Grid Track is between Row Lines 2 and 3.
  • 22. Grid Cell The smallest unit on our grid, a Grid Cell is the space between four Grid Lines. It’s just like a table cell. The highlighted Grid Cell is between row lines 2 and 3 and column lines 2 and 3.
  • 23. Grid Area Any area of the Grid bound by 4 Grid Lines. It can contain many Grid Cells. The highlighted Grid Area is between row lines 1 and 3, column lines 2 and 4.
  • 24. All examples can be found at http://gridbyexample.com. Use Chrome. Enable “Experimental Web Platform Features” flag.
  • 27. The HTML around my page content. The various areas of my page are child elements of a div with a class of wrapper. <div class="wrapper"> <header class="mainheader"></header> <div class="panel"></div> <div class="content"></div> </div>
  • 29. Declaring a grid on wrapper. The grid has three columns, and four rows. .wrapper { width: 100%; max-width: 960px; margin: 0 auto; display: grid; grid-template-columns: 30% 5% 65%; grid-template-rows: 40px auto 20px auto; }
  • 31. Positioning our elements using the grid-column and grid-row shorthand. This is all we need to do to create our layout. .mainheader { grid-column: 1 / 4; grid-row: 2 / 3; } .panel { grid-column: 1 / 2; grid-row: 4 / 5; } .content { grid-column: 3 / 4; grid-row: 4 / 5; }
  • 34. I can add a footer to this layout - and it doesn’t matter in which unusual place I want to add the markup. <div class="wrapper"> <header class="mainheader"></header> <footer class="mainfooter"></footer> <div class="panel"></div> <div class="content"></div> </div>
  • 35. Positioning the footer between row lines five and six. .mainfooter { grid-column: 1 / 4; grid-row: 5 / 6; }
  • 37. Our grid only has 5 row lines specified - yet we placed an item between row lines 5 and 6. Grid creates an implicit grid line for us. .wrapper { display: grid; grid-template-columns: 30% 5% 65%; grid-template-rows: 40px auto 20px auto; } .mainfooter { grid-column: 1 / 4; grid-row: 5 / 6; }
  • 38. Grid lines can be explicit or implicit • Explicit grid lines are those that you specify and give sizing information.
 • Implicit lines are created when you place something into a row or column you have not specified with grid-template-rows or grid- template-columns
  • 39. Grid is “table like” however … • Unlike a table for layout Grid does not rely on your content being a particular order in the source.
 • Being entirely described in CSS we can move things around the Grid at different breakpoints, introduce or redefine a Grid for any breakpoint.
  • 40. Using Grid to order the page elements in a single column for narrow screen widths. .wrapper { display: grid; grid-template-rows: 10px auto 10px auto 10px auto 10px auto; } .mainheader { grid-row: 2 / 3; } .content { grid-row: 4 / 5; } .panel { grid-row: 6 / 7; } .mainfooter { grid-row: 8 / 9; }
  • 42. Redefine the Grid at min- width 550 pixels. Position items as in the earlier example. @media (min-width: 550px) { .wrapper { grid-template-columns: 30% 5% 65%; grid-template-rows: 40px auto 20px auto 20px auto; } .mainheader { grid-column: 1 / 4; grid-row: 2 / 3; } .panel { grid-column: 1 / 2; grid-row: 4 / 5; } .content { grid-column: 3 / 4; grid-row: 4 / 5; } .mainfooter { grid-column: 1 / 4; grid-row: 6 / 7; } }
  • 45. Name lines with the name in parenthesis. Remember we name grid lines and not grid tracks. .wrapper { display: grid; grid-template-rows: 10px (row-header-start) auto (row-header-end) 10px (row-content-start) auto (row-content-end) 10px (row-panel-start) auto (row-panel-end) 10px (row-footer-start) auto (row-footer-end); }
  • 46. Here we are positioning based on line numbers. .mainheader { grid-row: 2 / 3; } .content { grid-row: 4 / 5; } .panel { grid-row: 6 / 7; } .mainfooter { grid-row: 8 / 9; }
  • 47. Here we are positioning by named lines. .mainheader { grid-row: row-header-start / row-header-end ; } .content { grid-row: row-content-start / row-content-end; } .panel { grid-row: row-panel-start / row-panel-end ; } .mainfooter { grid-row: row-footer-start / row-footer-end; }
  • 50. We assign a name to the elements on our page. I am doing this outside of any Media Queries. .mainheader { grid-area: header; } .content { grid-area: content; } .panel { grid-area: sidebar; } .mainfooter { grid-area: footer; }
  • 51. Describe the layout on the parent element using the grid-template-areas property. A period “.” indicates that this grid cell is empty. .wrapper { display: grid; grid-template-rows: 10px auto 10px auto 10px auto 10px auto; grid-template-areas: "." "header" "." "content" "." "sidebar" "." "footer"; }
  • 54. Redefining the template areas for the wider layout. @media (min-width: 550px) { .wrapper { grid-template-columns: 30% 5% 65%; grid-template-rows: 2em auto 1em auto 1em auto; grid-template-areas: ". . ." "header header header" ". . ." "sidebar . content" ". . ." "footer footer footer" } }
  • 57. A 12 column, flexible grid
  • 59. You can use the repeat keyword to repeat all or part of the grid definition. This would create 4 200 pixel wide tracks, separated by a 20 pixel wide gutter track. grid-template-columns: repeat(4, 200px 20px);
  • 60. The fr unit is a flexible length that represents a fraction of the available space in the grid container. grid-template-columns: 5fr 1fr 10fr 1fr 5fr;
  • 61. We can give multiple grid lines the same name. This means we can use the span keyword to span n number of lines, rather than specifying a specific grid line. .wrapper { grid-template-columns: repeat(4, (col) 200px (gutter) 20px); } .content { grid-column: col 2 / span gutter 2; }
  • 62. The markup used to create the Grid using the Skeleton framework. Like the Bootstrap Grid and other similar frameworks it requires classes that describe the grid to be added to the markup. <div class="container"> <h1>Skeleton Grid</h1> <div class="example-grid"> <div class="row"> <div class="four columns">Four columns</div> <div class="four columns">Four columns</div> <div class="four columns">Four columns</div> </div> <div class="row"> <div class="eight columns">Eight columns</div> <div class="four columns">Four columns</div> </div> <div class="row"> <div class="three columns">Three columns</div> <div class="three columns">Three columns</div> <div class="three columns">Three columns</div> <div class="three columns">Three columns</div> </div> <div class="row"> <div class="six columns">Six columns</div> <div class="six columns">Six columns</div> </div> </div>
  • 64. When using CSS Grid Layout we have no need to describe our grid in markup. <div class="wrapper skeleton"> <h1 class="header">CSS Grid Layout Version</h1> <div class="box1">Four columns</div> <div class="box2">Four columns</div> <div class="box3">Four columns</div> <div class="box4">Eight columns</div> <div class="box5">Four columns</div> <div class="box6">Three columns</div> <div class="box7">Three columns</div> <div class="box8">Three columns</div> <div class="box9">Three columns</div> <div class="box10">Six columns</div> <div class="box11">Six columns</div> </div>
  • 65. Defining the 12 column grid. The repeat keyword repeats the pattern of columns or rows the number of times specified before the comma. .wrapper { display: grid; grid-template-columns: repeat(11, (col) 4fr (gutter) 3.5fr ) (col) 4fr (gutter); grid-template-rows: auto repeat(4, (row) auto (gutter) 15px); }
  • 66. Placing box1 on the grid. Multiple lines have the same name. This means we can use the span keyword. Here I place box1 starting at the first line named col, spanning to the 4th line named gutter. In the first row named row, spanning to the first line named gutter. .box1 { grid-column: col / span gutter 4; grid-row: row / span gutter; }
  • 67. Placing box8 on the grid. Starting on column line 7, spanning 3 gutter lines. In the 3rd row named row, spanning 1 gutter line. .box8 { grid-column: col 7 / span gutter 3; grid-row: row 3 / span gutter; }
  • 69. With Grid Layout we can easily span rows just like columns. .box1b { grid-column: col / span gutter 4; grid-row: row / span gutter 2; } .box2b { grid-column: col 5 / span gutter 4; grid-row: row / span gutter 3; }
  • 71. Browser Support All my examples work in Chrome and Opera unprefixed - you need to enable the Experimental Web Platform Features flag. You can also use Webkit nightlies, with the -webkit prefix. The work in Blink and Webkit is being done by Igalia, sponsored by Bloomberg. IE10 and up has support for the old syntax, with an -ms prefix. Mozilla are currently implementing Grid in Firefox. There is a Polyfill under active development: https://github.com/ FremyCompany/css-grid-polyfill/
  • 73. Thank you! Slides, links to examples and resources:
 http://rachelandrew.co.uk/presentations/css-grid Office Hours Today - 1.30pm Community Lounge. @rachelandrew me@rachelandrew.co.uk