Dominic Magnifico

Senior Front End Engineer @10up

Layout methods of the past

Tables ๐Ÿ™€

Tables Kind of
suck for layout

Tables aren't easily made responsive

Layout methods of the past

Tables ๐Ÿ™€

Layout methods of the past

Tables ๐Ÿ™€

When tables were used for layout, accessibility was not top of mind.

Box Model ย ยฏ\_(ใƒ„)_/ยฏ

Layout methods of the past

Where the box model excels

  • With floats we get (limited) control over the layout of single columns.
  • And we get the fancy ability to add space around these items.

Box Model ย ยฏ\_(ใƒ„)_/ยฏ

Layout methods of the past

Where the box model collapses

  • Starts to become a pain when we want granular control over items in a column
  • Equal spacing between divs
  • Same goes for row control
  • Vertical centering

Box Model ย ยฏ\_(ใƒ„)_/ยฏ

Layout methods of the past

Layout methods of the present

๐Ÿ˜ Flexbox ๐Ÿ˜

Where flexbox excels

Layout methods of the present

๐Ÿ˜ Flexbox ๐Ÿ˜

  • Much more granular control over how flex items behave in a column orย row.
  • Can grow, shrink, order, justify and align flex items. Lots of options.
  • Vertical andย horizontal centering. ๐Ÿคค

Where flexbox may lack a bit

Layout methods of the present

๐Ÿ˜ Flexbox ๐Ÿ˜

  • Though until grid, it worked better than a lot of the options we had at the time, so we overused it.

Layout methods of the present

๐Ÿ˜ Flexbox ๐Ÿ˜

Slow Connections

  • Flexbox has a tendency to shift on page load.
  • Content shifting during page load is super annoying for folks on slower connections.

Layout methods of the present

๐Ÿ˜ Flexbox ๐Ÿ˜

Get down to the nitty grid-dy

Let's start with terminology

Get to know the properties

Grid Displayย 

display: grid;

display: inline-grid;

display: subgrid;

Defining the Grid

Tracks


.grid {
  display: grid;
  grid-template-columns: [rinzler] 100px [flynn] 100px [quorra] 200px [sam] 150px
}

Line Names

Track Sizes

A NEW UNIT HAS ENTERED THE ARENA

What's the fr...iggen deal

The fr unit

  • The fr unit represents a fraction of the available space within a grid container.
.grid {
  display: grid;
  grid-template-columns: [rinzler] 1fr [flynn] 1fr [quorra] 1fr [sam] 1fr
}

Enter, repeat()

Ughghchk So much typing

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

Grid track start and end

minmax()

  • Defines a size range greater than or equal to min and less than or equal to max

Auto-placement to the rescue!

More auto-placement

  • grid-auto-flow: sparse

More auto-placement

  • grid-auto-flow: dense

Ugh, ya right, what about browser support?

https://rachelandrew.co.uk/css/cheatsheets/grid-fallbacks

Further grid exploration

Dominic Magnifico

Senior Front End Engineer @10up

Made with Slides.com