171
CSS GRID CHANGES EVERYTHING (SHIFTING THE WEB LAYOUT PARADIGM) Morten Rand-Hendriksen | @mor10 | WebCamp Zagreb 2017

CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Embed Size (px)

Citation preview

Page 1: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

CSS GRID CHANGES EVERYTHING (SHIFTING THE WEB LAYOUT PARADIGM)

Morten Rand-Hendriksen | @mor10 | WebCamp Zagreb 2017

Page 2: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 3: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

mor10.com/wczg2017SLIDES, LINKS, ETC:

@mor10 #CSSGrid #WCZG

Page 4: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 5: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 6: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 7: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 8: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 9: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 10: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Paradigm Shift

Page 11: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Desire Path

Page 12: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 13: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 14: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 15: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Pave the cowpath

To formalize an existing de-facto practice.

Page 16: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Desire Path: A Short History of Web Design

Page 17: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1990

Tim Berners-Lee publishes first ever web page.

Page 18: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1990

Web as

text period

Page 19: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Web as

text period

1990

 Håkon Wium Lie proposes Cascading Style Sheets

1994

Page 20: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1990

Web as

text period

1994

Dar

k A

ges

Page 21: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Web as

text period D

ark

Age

s

1990

Lynda Weinman publishes Designing with Web Graphics

1996

Page 22: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1990 1996

Wild West period

- Tables Frames Flash

“Pixel-perfect”

Web as

text period

1994

Dar

k A

ges

Page 23: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Wild West period

- Tables Frames Flash

“Pixel-perfect”

Web as

text period D

ark

Age

s

1990

Jeffrey Zeldman publishes Designing with Web Standards

20031996

Page 24: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1990 20031996

Web Standards Period

- Floats Clears Blogs

“Web 2.0” CSS layout hell

Web as

text period

1994

Dar

k A

ges

Wild West period

- Tables Frames Flash

“Pixel-perfect”

Page 25: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 26: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 27: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 28: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 29: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 30: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Web Standards Period

- Floats Clears Blogs

“Web 2.0” CSS layout hell

Web as

text period D

ark

Age

s

Wild West period

- Tables Frames Flash

“Pixel-perfect”

1990 20031996 2012

Microsoft releases Windows 8

Page 31: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Web Standards Period

- Floats Clears Blogs

“Web 2.0” CSS layout hell

Web as

text period D

ark

Age

s

Wild West period

- Tables Frames Flash

“Pixel-perfect”

1990 20031996 2012

Microsoft proposes CSS Grid Layout

Page 32: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Web Standards Period

- Floats Clears Blogs

“Web 2.0” CSS layout hell

Web as

text period D

ark

Age

s

Wild West period

- Tables Frames Flash

“Pixel-perfect”

1990 20031996 2015

display: flex;

2012

Page 33: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1990 20031996 2015

Web Standards Period

- Floats Clears Blogs

“Web 2.0” CSS layout hell

Web as

text period

1994

Dar

k A

ges

Wild West period

- Tables Frames Flash

“Pixel-perfect”

Un

cert

ain

ty P

erio

d

Page 34: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 35: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 36: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

meanwhile…

Page 37: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Rachel Andrew @rachelandrew

Jen Simmons @jensimmons

Page 38: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Web Standards Period

- Floats Clears Blogs

“Web 2.0” CSS layout hell

Web as

text period D

ark

Age

s

Wild West period

- Tables Frames Flash

“Pixel-perfect”

Un

cert

ain

ty P

erio

d

1990 201720031996 2015

display: grid;

2012

Page 39: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1990 20031996 2015

Web Standards Period

- Floats Clears Blogs

“Web 2.0” CSS layout hell

Web as

text period

1994

Dar

k A

ges

Wild West period

- Tables Frames Flash

“Pixel-perfect”

Un

cert

ain

ty P

erio

d

2017

Web as

Layout Surface

Page 40: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 41: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 42: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 43: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Pave the cowpath

To formalize an existing de-facto practice.

Page 44: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 45: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 46: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 47: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 48: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Person behind you

What did I just watch?!?!

Page 49: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

https://codepen.io/mor10/full/JrpRyv/

Page 50: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 51: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

CSS Grid makes the impossible possible

Page 52: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 53: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 54: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 55: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 56: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 57: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 58: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 59: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

<div class="MomentsGuidePage-capsules"> <div class="MomentsCapsuleSummaryGroup"> <div class="MomentsCapsuleSummary--hero"></div> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> </div> <div class="MomentsCapsuleSummaryGroup"> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> </div>

Page 60: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

2

3

4

8

9

10

5

6

7

1

Page 61: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

2

3

4

8

9

10

5

6

7

1

Page 62: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

2

3

4

1

Page 63: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

2

3

4

8

9

10

5

6

7

1

Page 64: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

10 10

2

3

4

8

9

10

5

6

7

1

11

12

14

15

Page 65: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

11 1312

10

14

9

10

2 3

4

8

5

6 7

1

15

Page 66: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Since the beginning of (web) time, web layouts have been broken.

We’ve just refined how we break them.

Page 67: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.main-content .sidebar

.container

Page 68: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.main-content

.sidebar

.wrap.wrap { border: 5px solid red; }

.main-content { background: blue; }

.sidebar { background: green; }

Page 69: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.main-content .sidebar

.wrap.wrap { border: 5px solid red; }

.main-content { width: 45%; float: left; background: blue; }

.sidebar { width: 45%; float: right; background: green; }

Page 70: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.main-content .sidebar

.wrap.wrap { border: 5px solid red; }

.main-content { width: 45%; float: left; background: blue; }

.sidebar { width: 45%; float: right; background: green; }

/* Clearfix */ .wrap:after { content: ""; display: table; clear: both; }

Page 71: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.main-content .sidebar

.wrap.wrap { display: flex; justify-content: space-between; border: 5px solid red; }

.main-content { width: 45%; background: blue; }

.sidebar { width: 45%; background: green; }

Page 72: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.main-content .sidebar

.wrap

.other-content

Page 73: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.main-content .sidebar

.wrap

.other-content

.container

Page 74: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.main-content .sidebar

.wrap.wrap { display: flex; justify-content: space-between; border: 5px solid red; }

.container { width: 45%; }

.main-content { background: blue; }

.other-content { background: purple; }

.sidebar { width: 45%; background: green; }

.container

.other-content

Page 75: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

This is a hack.

float and flex force us to create HTML clutter in the form of wrappers like the .container element in this example.

.main-content .sidebar

.wrap.container

.other-content

Page 76: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

This is web layouts today.

float and flex have been the two only options for creating horizontal layouts resulting in the web suffering from a severe case of Divitis.

.main-content .sidebar

.wrap.container

.other-content

Page 77: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

http://getbootstrap.com/css/

Page 78: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 79: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Paal Joachim Romdahl on Advanced WordPress Group

Page 80: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Me, every time I build a new site

What if we didn’t have to do this any more…

Page 81: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

<div class="MomentsGuidePage-capsules"> <div class="MomentsCapsuleSummaryGroup"> <div class="MomentsCapsuleSummary--hero"></div> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> </div> <div class="MomentsCapsuleSummaryGroup"> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> </div>

Page 82: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 83: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 84: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

<div class="MomentsGuidePage-capsules"> <div class="MomentsCapsuleSummaryGroup"> <div class="MomentsCapsuleSummary--hero"></div> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> </div> <div class="MomentsCapsuleSummaryGroup"> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> </div>

Page 85: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

<div class="MomentsGuidePage-capsules"> <div class="MomentsCapsuleSummaryGroup"> <div class="MomentsCapsuleSummary--hero"></div> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> </div> <div class="MomentsCapsuleSummaryGroup"> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> <div class="MomentsCapsuleSummaryGroup-list"> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div> </div>

Page 86: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

<div class="MomentsGuidePage-capsules"> <div class="MomentsCapsuleSummary--hero"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> <div class="MomentsCapsuleSummary--portrait"></div> </div>

Page 87: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

<ul class="MomentsGuidePage-capsules"> <li class="MomentsCapsuleSummary--hero"></li> <li class="MomentsCapsuleSummary"></li> <li class="MomentsCapsuleSummary"></li> <li class="MomentsCapsuleSummary"></li> <li class="MomentsCapsuleSummary"></li> <li class="MomentsCapsuleSummary"></li> <li class="MomentsCapsuleSummary"></li> <li class="MomentsCapsuleSummary"></li> <li class="MomentsCapsuleSummary"></li> <li class="MomentsCapsuleSummary"></li> </ul>

Page 88: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Problem:

Current tools for web layout are

content-out and one-dimensional.

Solution:

Two-dimensional layout-in tool to separate content

from presentation.

Page 89: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 90: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 91: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1

2

3

4

5 6

Page 92: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 93: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

You, right now

OK, I’m listening…

Page 94: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site

.page-title

.main-content

.sidebar .footer

.masthead

<div class="site"> <header class="masthead"> </header>

<h1 class="page-title"> </h1>

<main class="main-content"> </main>

<aside class="sidebar"> </aside>

<footer class="footer"> </footer>

</div><!-- .site -->

Page 95: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

• Grid container • Grid item • Grid line • Grid cell • Grid track • Grid area • Grid gap

CSS Grid Terminology:

Page 96: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Element containing a grid,

defined by setting display: grid;

Grid container <div class="site"> <header class="masthead"> </header>

<h1 class="page-title"> </h1>

<main class="main-content"> </main>

<aside class="sidebar"> </aside>

<footer class="footer"> </footer>

</div><!-- .site -->

Page 97: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Element that is a direct

descendant of the grid

container.

Grid item <div class="site"> <header class="masthead"> </header>

<h1 class="page-title"> </h1>

<main class="main-content"> </main>

<aside class="sidebar"> </aside>

<footer class="footer"> </footer>

</div><!-- .site -->

Page 98: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Horizontal (row) or

vertical (column) line

separating the grid into

sections.

Grid line

Page 99: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Grid lines are referenced

by number, starting and

ending with the outer

borders of the grid.

Grid line 1

2

3

4

5

6

1 2 3 4 5 6

Page 100: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

The intersection between

a grid row and a grid

column. Effectively the

same as a table cell.

Grid cell

Page 101: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Rectangular area between

four specified grid lines.

Grid areas can cover one

or more cells.

Grid area

Page 102: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

The space between two or

more adjacent grid lines.

Row tracks are horizontal,

Column tracks vertical.

Grid track

Page 103: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Empty space between grid

tracks (shown in blue).

Commonly called gutters.

Grid gap 1

2

3

4

5

6

1 2 3 4 5 6

Page 104: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

The person next to you

I’ll pretend I got that…

Page 105: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1. Define a grid.

2. Place items within the grid.

3. Make world peace.

CSS Grid in a Nutshell:

Page 106: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

<div class="site"> <header class="masthead"> </header>

<h1 class="page-title"> </h1>

<main class="main-content"> </main>

<aside class="sidebar"> </aside>

<footer class="footer"> </footer>

</div><!-- .site -->

.masthead

.page-title

.main-content

.sidebar

.footer

.site

Page 107: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

<div class="site">

</div><!-- .site -->

.masthead

.page-title

.main-content

.sidebar

.footer

.site

Page 108: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site

Creates a grid container.

display: grid;

Page 109: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site

2 fractions 1 fraction each

2fr 1fr 1fr

Draws grid lines. Takes list of length values (em, px, %,

fr, etc.) denoting the distance between each line.

grid-template-columns: 2fr 1fr 1fr;

Page 110: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site

Fit content

auto

1 fraction

1fr

3 fractions

3fr

Draws grid lines. Takes list of length values (em, px, %,

fr, etc.) denoting the distance between each line.

grid-template-rows: auto 1fr 3fr;

Page 111: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.masthead .page- title

.main- content

.sidebar .footer

.site

Grid items automatically

populate grid from top left

to bottom right based on

HTML source order.

Page 112: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site1 2 3 4

.masthead

grid-column: 2/4; grid-row: 2/3;

Applied to grid items. Defines the start and end grid lines

for columns and rows.

Page 113: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site1 2 3 4

Start at column line 2. End at column line 4.

.masthead

grid-column: 2/4; grid-row: 2/3;

Page 114: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.masthead

.masthead

.site1

2

3

4

Start at row line 2. End at row line 3.

grid-column: 2/4; grid-row: 2/3;

Page 115: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site.site { display: grid; grid-template-columns: 2fr 1fr 1fr; grid-template-rows: auto 1fr 3fr; }

.masthead { grid-column: 2/4; grid-row: 2/3; }

.page-title { grid-column: 1/4; grid-row: 1/2; }

.main-content { grid-column: 1/2; grid-row: 2/4; }

/* etc etc */

1

2

3

4

1 2 3 4

.page-title

.main-content

.sidebar .footer

.masthead

Page 116: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Naysayer to your left

Looks promising, but remembering what lines to target seems tricky… especially when the site is responsive.

Page 117: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site

title title title

main

main

header header

sidebar footer

Applied to grid container. Uses a text-based grid map to apply grid

area names to individual cells.

grid-template-areas

Page 118: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site { display: grid; grid-template-columns: 2fr 1fr 1fr; grid-template-rows: auto 1fr 3fr; grid-template-areas: "title title title" "main header header" "main sidebar footer"; }

Page 119: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Specifies what grid area the element is placed within.

grid-area: [area-name];

Page 120: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

title title title

main

main

header header

sidebar footer

.page-title

.main-content

.sidebar .footer

.masthead

.site.site { display: grid; grid-template-columns: 2fr 1fr 1fr; grid-template-rows: auto 1fr 3fr; grid-template-areas: "title title title" "main header header" "main sidebar footer"; }

.masthead { grid-area: header; }

.page-title { grid-area: title; }

.main-content { grid-area: main; }

/* etc etc */

Page 121: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr 3fr; grid-template-areas: "title title" "main header" "main sidebar"; }

.masthead { grid-area: header; }

.page-title { grid-area: title; }

.main-content { grid-area: main; }

.sidebar { grid-area: sidebar; }

.footer { grid-area: footer; }

@media screen and (min-width: 34em) {

.site { grid-template-columns: 2fr 1fr 1fr; grid-template-areas: "title title title" "main header header" "main sidebar footer"; }

}

Page 122: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site

.page-title

.main-content

.sidebar .footer

.masthead

.site

.page-title

.main-content

.sidebar

.footer

.masthead

.site

.masthead

.page-title

.main-content

.sidebar

.footer

No grid Two-column grid Three-column grid

Page 123: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Girds are not inherited by

child elements. Instead we

create nested grids.

Nested grids

Page 124: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 125: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 126: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

You, right now

Sooooooo… no more floats and clears?

Page 127: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Use CSS Grid any time you work with two-dimensional layouts.

Page 128: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

One more thing

Page 129: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

The grid container is a flexible box.

Page 130: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 131: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site { display: grid; grid-template-columns: repeat(6, 10em); grid-gap: 1em; }

Page 132: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site { display: grid; grid-template-columns: repeat(6, 10em); justify-content: center; grid-gap: 1em; }

Page 133: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site { display: grid; grid-template-columns: repeat(6, 10em); justify-content: space-between; grid-gap: 1em; }

Page 134: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

.site { display: grid; grid-template-columns: repeat(6, 10em); justify-content: space-between; grid-gap: 1em; }

Page 135: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

repeat(auto-fit, 10em); repeat(auto-fill, 10em);

Page 136: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 137: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Creates as many 10em columns as will fit within the grid container.

Will create empty columns.

grid-template-columns: repeat(auto-fill, 10em);

Page 138: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Creates as many 10em columns as will fit within the grid container.

Does not create empty columns.

grid-template-columns: repeat(auto-fit, 10em);

Page 139: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

https://codepen.io/mor10/pen/MEQJbM

Page 140: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Your boss / client

… but older browsers!

Page 141: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

http://caniuse.com/#search=grid

Grid is supported in all modern browsers.

Page 142: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

The elephants in the room

Page 143: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Internet Explorer 101 and Edge2 lag behind*

1 IE10 uses the original Grid specification. 2 Edge is adopting the modern specification October 17th. * Fun fact: CSS Grid was invented by Microsoft for IE10.

Page 144: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Use feature queries to test for grid support in the current browser.

@supports (display: grid) { … }

Current recommendation:

Page 145: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

HOLD ON THERE MORTEN!

Page 146: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Everyone right now

That means the site won’t look the same in all browsers!

Page 147: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

If it works here…

… it works here as well!

Page 148: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Forcing sites to look the same across all browsers

is a bad habit.

Page 149: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Responsive Web Design means we’ve been serving up

different layouts for different browsers since 2010.

Page 150: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Progressive Enhancement is Responsive Web Design

in three dimensions.

Page 151: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Accessible mobile-first layouts work well on all screen widths.

Page 152: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 153: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 154: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 155: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Page 156: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Embrace Progressive Enhancement! Use the paved desire paths!

Page 157: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1. Build accessible mobile-first layout without grid.

2. Use mobile-first layout as fallback for all browsers.

3. Use @supports to detect grid support.

4. At the appropriate breakpoint, create layout with grid and grid-areas.

5. Explore new layouts as viewport widens.

CSS Grid: A Practical Approach for Today

Page 158: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

More CSS Grid info:

Page 159: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Firefox has a grid inspector!

https://goo.gl/SJmlms

Page 160: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Rachel Andrew’s Grid by Example is doctrine.

https://gridbyexample.com/

Page 161: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Rachel Andrew’s book The New CSS Layout comes out next week.

https://goo.gl/LY6cFy

Page 162: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

MDN has exhaustive documentation.

https://goo.gl/8RrH2Y

Page 163: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Mozilla’s CSS Grid Playground is a great place to get the basics.

https://goo.gl/rmbkM5

Page 164: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Mozilla also has a demo site with has exhaustive documentation.

https://goo.gl/wa0Fk9

Page 165: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

CSS Tricks has a Complete Guide to CSS Grid.

https://goo.gl/Z01gjF

Page 166: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Kuhn, my theme using CSS grid, is on GitHub to give you ideas.

https://goo.gl/URouSh

Page 167: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Building Production-Ready CSS Grid Layouts Today by yours truly at Smashing Magazine

https://goo.gl/dae838

Page 168: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Free for everyone until October 25th, 2017! https://goo.gl/wyC1Lz

Page 169: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

Go build your own Desire Paths.

Page 170: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017

1. Make it accessible.

2. Make it fancy.

3. Make sure the fancy doesn’t break accessibility.

Page 171: CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017