Chapter 1. Grid Layout
For as long as CSS has existed—which is, believe it or not, two decades
now—it’s had a layout-shaped hole at its center. We’ve bent other
features to the purposes of layout, most notably
and generally hacked our way around that hole. Flexbox layout helped to
fill it, but flexbox is really meant for only specific use cases, like
navigation bars (navbars).
Grid layout, by contrast, is a generalized layout system. With its emphasis on rows and columns, it might at first feel like a return to table layout—and in certain ways that’s not too far off—but there is far, far more to grid layout than table layout. Grid allows pieces of the design to be laid out independently of their document source order, and even overlap pieces of the layout, if that’s your wish. There are powerfully flexible methods for defining repeating patterns of grid lines, attaching elements to those grid lines, and more. You can nest grids inside grids, or for that matter, attach tables or flexbox containers to a grid. And much, much more.
In short, grid layout is the layout system we’ve long waited for. There’s a lot to learn, and perhaps even more to unlearn, as we leave behind the clever hacks and workarounds that have gotten us through the past 20 years.
Before we get started, a word of caution: as I write this in April 2016, grid layout is still in a bit of flux. We literally delayed publication twice due to changes in the specification and supporting browsers, ...