91
Slides & resources https://noti.st/rachelandrew Grids All The Way Down @rachelandrew at Pixel Pioneers

Grids All The Way Down - on.notist.cloudSlides & resources CSS Grid Layout Two years on

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Grids All The Way Down@rachelandrew at Pixel Pioneers

Page 2: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Doing things on the web since 1996

Co-founder Perch CMS & Notist. Editor in Chief Smashing Magazine. Writer of many books. CSS Working Group Member representing Fronteers. Spec editor Multicol and Page Floats.

MDN tech writer.

Page 3: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

CSS Grid LayoutTwo years on.

Page 4: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

“I can make flexbox do anything. Why should I learn grid?”

Page 5: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

“Should I use colour in this web design, or will fonts do?”

Page 6: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

“Should I build my site using Flexbox or Grid?”

Page 7: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Stop thinking about Flexbox & Grid as two

separate layout methods

Page 8: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Should I build my site using Flexbox or Grid?

YES.

Page 9: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 10: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Look at the pattern you need to build.

That will tell you which layout method you need.

Page 11: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Flexbox when you have a bunch of different size

stuff you want displayed in a readable way.

Page 12: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 13: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Grid for when you want to control the structure and place items into it.

Page 14: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 15: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

If you are putting widths on all your flex items to make them line up. You

probably want grid.

Page 16: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 17: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 18: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

/* grid */.airplanes {display: grid;grid-gap: 5vh;grid-template-columns: repeat(auto-fill, minmax(400px, auto));grid-auto-rows: 45vh;

}

/* flex */.airplanes {display: flex;flex-wrap: wrap;

}

.airplanes li {flex: 1 1 400px;height: 45vh;margin: 2vh 10px;

}

Page 19: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 20: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Two-dimensionalGrid works in the same way in both axes.

Page 21: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Inline dimension: the grid fills the grid container

Block dimension:as tall as is needed for the content.

Page 22: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Inline dimension: the grid fills the grid container

Block dimension:the grid fills the grid container

Page 23: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.grid {display: grid;grid-template-columns: repeat(3, 1fr);grid-template-rows: repeat(3,100px);gap: 5px;

}

Page 24: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.grid {display: grid;grid-template-columns: repeat(3, 1fr);grid-template-rows: repeat(3,100px);gap: 5px;

}

Page 25: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.grid {display: grid;grid-template-columns: repeat(3, 1fr);grid-template-rows:

repeat(3, minmax(100px,auto));gap: 5px;

}

Page 26: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

We have choices now!Enjoy them, they have been a long time coming.

Page 27: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 28: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 29: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 30: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

What can’t we do yet?

Page 31: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 32: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

figure {display: grid;height: 100%; grid-template-columns: 1fr 3fr;grid-template-rows: 1fr minmax(1em, auto);

}

Page 33: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Only direct children become grid or flex items.

Their children return to normal flow.

Page 34: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 35: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 36: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 37: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

1 2

43

Page 38: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

display: contentsRemoving the box from the layout.

Page 39: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 40: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

<!--HTML--><div class="grid"><div>Direct Child</div><div>Direct Child</div><ul><li>List Item</li><li>List Item</li><li>List Item</li>

</ul><div>Direct Child</div>

</div>

Page 41: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

/* CSS */.grid {display: grid;grid-template-columns: repeat(3, 1fr);

}

.grid > * {background-color: rgba(255,255,255,.5);

}

ul > * {background-color: rgb(209,54,114);

}

ul {

}

Page 42: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

/* CSS */.grid {display: grid;grid-template-columns: repeat(3, 1fr);

}

.grid > * {background-color: rgba(255,255,255,.5);

}

ul > * {background-color: rgb(209,54,114);

}

ul {display: contents;

}

Page 43: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 44: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

SubgridCreate a grid on a grid item which uses the grid tracks defined

on the parent – for rows, columns or both.

Page 45: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.grid {display: grid;grid-template-columns: repeat(9, 1fr);grid-template-rows: repeat(4, minmax(100px,

auto));}

.item {grid-column: 2 / 7;grid-row: 2 / 4;display: grid;grid-template-columns: repeat(3, 1fr);grid-template-rows: repeat(3, 80px);

}

.subitem {grid-column: 2 / 4;grid-row: 1 / 4;

}

Page 46: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 47: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 48: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 49: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.grid {display: grid;grid-template-columns: repeat(9, 1fr);grid-template-rows: repeat(4, minmax(100px,

auto));}

.item {grid-column: 2 / 7;grid-row: 2 / 4;display: grid;grid-template-columns: subgrid;grid-template-rows: repeat(3, 80px);

}

.subitem {grid-column: 3 / 6;grid-row: 1 / 4;

}

Page 50: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.grid {display: grid;grid-template-columns: repeat(9, 1fr);grid-template-rows: repeat(4, minmax(100px,

auto));}

.item {grid-column: 2 / 7;grid-row: 2 / 4;display: grid;grid-template-columns: repeat(3, 1fr);grid-template-rows: subgrid;

}

.subitem {grid-column: 2 / 4;grid-row: 1 / 3;

}

Page 51: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.grid {display: grid;grid-template-columns: repeat(9, 1fr);grid-template-rows: repeat(4, minmax(100px,

auto));}

.item {grid-column: 2 / 7;grid-row: 2 / 4;display: grid;grid-template-columns: subgrid;grid-template-rows: subgrid;

}

.subitem {grid-column: 3 / 6;grid-row: 1 / 3;

}

Page 52: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Line numbers start from 1 inside the subgrid.

You position child items in the subgrid according to the subgridline numbering, not those of the parent.

Page 53: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 54: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Line names on the parent are passed into the subgrid.If you have named lines on the parent grid they will be passed

into the subgrid and added to any names defined there.

Page 55: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

col-start col-end

col-start col-end

Page 56: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.grid {display: grid;grid-template-columns:1fr 1fr 1fr [col-start] 1fr 1fr 1fr [col-end] 1fr 1fr 1fr;grid-template-rows: repeat(4, minmax(100px, auto));

}

.item {grid-column: 2 / 7;grid-row: 2 / 4;display: grid;grid-template-columns: subgrid;grid-template-rows: subgrid;

}

.subitem {grid-column: col-start / col-end;grid-row: 1 / 3;

}

Page 57: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

You can add named lines to the subgrid.

Line names are added after the subgrid keyword.

Page 58: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

col-start col-end

sub-b sub-d

Page 59: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.grid {display: grid;grid-template-columns: 1fr 1fr 1fr [col-start] 1fr 1fr 1fr [col-end] 1fr 1fr 1fr;grid-template-rows: repeat(4, minmax(100px, auto));

}

.item {grid-column: 2 / 7;grid-row: 2 / 4;display: grid;grid-template-columns: subgrid [sub-a] [sub-b] [sub-c] [sub-d] [sub-e] [sub-f];grid-template-rows: subgrid;

}

.subitem {grid-column: col-start / col-end;grid-row: 1 / 3;

}

.subitem {grid-column: sub-b / sub-d;grid-row: 1 / 3;

}

Page 60: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

The subgrid inherits the gaps from the parent.

Page 61: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 62: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

You can change the gaps on the subgrid.

Page 63: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 64: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Sizing of items in the subgrid can change the size of the parent tracks.

Page 65: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 66: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Solved by subgrid …

Page 67: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 68: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.wrapper {display: grid;gap: 10px;grid-template-columns: repeat(5, 1fr);/* 5 explicit rows */grid-template-rows: repeat(5, minmax(100px, auto));

}

.fullheight {background-color: rgb(209,54,114);grid-row: 1 / -1;

}

Page 69: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Line -1 is the end line of the explicit grid.

Page 70: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 71: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.wrapper {display: grid;gap: 10px;grid-template-columns: repeat(5, 1fr);/* no defined explicit rows */grid-auto-rows: minmax(100px, auto);

}

.fullheight {background-color: rgb(209,54,114);grid-row: 1 / -1;

}

Page 72: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

We can’t target the end line of the implicit grid.

Page 73: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Place the items in a container which uses a

subgrid for columns

Page 74: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 75: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

.wrapper {display: grid;gap: 10px;grid-template-columns: repeat(5, 1fr);/* no defined explicit rows */grid-auto-rows: minmax(100px, auto);

}.items {grid-column: 2 / -1;display: grid;grid-template-columns: subgrid;grid-auto-rows: minmax(100px, auto);

}.fullheight {background-color: rgb(209,54,114);grid-row: 1 / -1;

}

Page 76: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Now the bad news

Page 77: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 78: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Slightly better newsSubgrid is in Firefox Nightly!

Page 79: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 80: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Fewer rendering enginesfewer places where new ground can be broken.

Page 81: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Tell browsers what you want in the platform.

Page 82: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 83: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

https://bugs.chromium.org/p/chromium/issues/detail?id=618969

Page 84: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Write about features you want to see in browsers

Write up your use cases, the problems having the feature will solve.

Page 85: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Use new features Browsers are watching.

Page 86: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 87: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Use new features when they are behind a flag

You get to beta test the web platform!

Page 88: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Give feedback to the CSS Working Group

https://github.com/w3c/csswg-drafts/issues

Page 89: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Page 90: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Participate in the web platformOr you are leaving your future as a designer or developer in

the hands of the very few who do.

Page 91: Grids All The Way Down - on.notist.cloudSlides & resources  CSS Grid Layout Two years on

Slides & resources https://noti.st/rachelandrew

Thank you@rachelandrew