In this lesson, you turned the seed swap page into a page shell: <body> as a grid of three rows that keeps the footer at the bottom of the window when the page is short, and lets it move down when the page is long.
Key Points
- With the banner’s
min-heightunticked in the Styles pane, the seed swap page is shorter than the window, and the footer sits right under the seed list with an empty band of page below it. A footer floating halfway up the window makes a page look unfinished, and any page with little on it, or a tall screen, shows it. <body>has three children, the header,<main>and the footer. Withdisplay: gridon<body>, each child gets a row of its own. One column sounds like flexbox, but here the sizes come from the layout in, from the window’s height, and that’s grid’s side.grid-template-rows: auto 1fr autolists the rows from top to bottom.1frtakes whatever space is left over, and that goes to<main>. Anautorow can stretch into spare space too, as the banner’s row did, but the1frrow takes all of it first, so the header and footer rows stay as tall as their content.min-height: 100vhmakes the body at least as tall as the window. Without it, the body is only as tall as its content, and there’s nothing left over for the row for<main>.- On the short page, the footer now sits at the bottom of the window. DevTools’ grid overlay on
<body>numbers four row lines, three rows, with the row for<main>filling the space between. - In normal flow, a block with no width set takes all the width it can, up to its
max-widthof 800 pixels, and auto side margins center it. In a grid, it’s the grid that stretches an item across its cell, and auto side margins switch that off. The page’s column gives the header,<main>and the footermargin-inline: auto, so each one shrinks to fit its content, and the margins share out the space on either side: the header shrank to 292.3 pixels and the footer to 382.09. <main>follows the same rule, but its seed tags, all on one line, would run wider than the column, so fitting its content still fills it. On the upcoming events page,<main>shrinks too, to 698.52 pixels.width: 100%on the three boxes makes each fill its cell again. The column’smax-widthstill stops it at 800 pixels, and the auto margins center it. The reset’sbox-sizing: border-boxkeeps the column’s side padding inside that width, so no box spills past the column.- On a page taller than the window, the footer goes below the seed list, past the bottom of the window: the row for
<main>has no space left over to share, and the body’s height is only a minimum, so it grows with the content.
Final Code
The two rules at the end of events/layout.css: