Grid is all about the container

I’ve been at Render Conference in Oxford with my first conference presentation on Grid, since it shipped into browsers this month. A short talk, I decided to deal with the most frequently asked of frequently asked questions:

  • Why is grid different to flexbox?
  • How do I get started with grid?
  • What about those old browsers?

I’ve explained the difference between grid and flexbox on this site, and also in an answer on my CSS Grid AMA. However now I’m starting to see people actually use grid for real, I realise that one of the places people are confused points to a fundamental difference in grid to everything that has come before.

Our layout methods have always been about the item

Everything else we do concentrates on the item in the layout. To create a float grid, you need to give the items in the layout a width and float them. The same is true for inline-block. Even flex items – while we create a flex layout on the container – if you want to start trying to make a grid you need to add widths or use the flex properties on the item that you are trying to place.

Grid is different. With grid you create layout and do space distribution on the container. The items then fit into that layout.

Unless your layout can be completely auto-placed, you are going to target the items in some way. However you are then controlling how they sit in that space you have created, as opposed to using the items themselves to force the size of columns.

In practice, I am finding that this turns out to be a big reason to choose grid over flexbox – even if you are essentially laying something out in one dimension. If you want to control the size and spacing of the items from the container, that’s what grid does really well.

The slides and code examples from my talk are online, and there will be a video posted soon.

76 Comments

Jeff Spicer April 29, 2017 Reply

That’s very interesting. I come from Adobe Flex, where these types of layouts were commonplace… with the decline of Flash Player, I’m glad to see that layout containers like this are coming back. I’m actually making on in GameMaker to run in HTML5.

Imran Ahmad August 22, 2017 Reply

@SaraSoueidan rachelandrew.co.uk/archives/2017/… plus youtube.com/watch?v=tjHOLt… might help.

Alia Adel October 13, 2017 Reply

A cheatsheet of Grid Layout fallbacks and overrides #MirrorConf buff.ly/2yiNyo2

Alia Adel October 13, 2017 Reply

Grid is all about the container – differences between grid and flexbox #MirrorConf buff.ly/2ydNzcU

Chris Heilmann October 13, 2017 Reply

Grid is all about the container – differences between grid and flexbox #MirrorConf buff.ly/2ydNzcU

Daniel H Pavey October 13, 2017 Reply

Grid is all about the container – differences between grid and flexbox #MirrorConf buff.ly/2ydNzcU

Derren Wilson October 13, 2017 Reply

Grid is all about the container – differences between grid and flexbox #MirrorConf buff.ly/2ydNzcU

Uziel Bueno October 13, 2017 Reply

A cheatsheet of Grid Layout fallbacks and overrides #MirrorConf buff.ly/2yiNyo2

Doug Collins October 13, 2017 Reply

Grid is all about the container – differences between grid and flexbox #MirrorConf buff.ly/2ydNzcU

Yann Isabel October 16, 2017 Reply

Grid is all about the container – differences between grid and flexbox #MirrorConf buff.ly/2ydNzcU

Benoit Larocque November 11, 2017 Reply

Explaining an interesting technique “Breaking out with CSS Grid Layout explained” buff.ly/2mh5Yks #DevFest17 #gdglondon https://t.co

nanad November 11, 2017 Reply

Grid Fallbacks and Overrides – using grid to overwrite older methods buff.ly/2ytgwyM

nanad November 11, 2017 Reply

More on why CSS Grid isn’t Masonry buff.ly/2yRtnik #DevFest17 #gdglondon

nanad November 11, 2017 Reply

Explaining an interesting technique “Breaking out with CSS Grid Layout explained” buff.ly/2mh5Yks #DevFest17 #gdglondon https://t.co

AndreaDSW November 11, 2017 Reply

on differences between grid and flexbox – Grid is all about the container #DevFest17 #gdglondon buff.ly/2zBYU5a

Naftali Friedman 🙂 November 11, 2017 Reply

Grid Fallbacks and Overrides – using grid to overwrite older methods buff.ly/2ytgwyM

Romain G November 11, 2017 Reply

Grid Fallbacks and Overrides – using grid to overwrite older methods buff.ly/2ytgwyM

jesterhead November 11, 2017 Reply

Explaining an interesting technique “Breaking out with CSS Grid Layout explained” buff.ly/2mh5Yks #DevFest17 #gdglondon https://t.co

Melissa November 11, 2017 Reply

GDGLondon part 2

V8 Internals For JavaScript Developers by @mathias

Solving Layout Problems With CSS Grid And Friends by @rachelandrew

#DevFest17 #GDGLondon




Becky Lingafelter November 11, 2017 Reply

Explaining an interesting technique “Breaking out with CSS Grid Layout explained” buff.ly/2mh5Yks #DevFest17 #gdglondon https://t.co

Leave a Reply