Spread the Header and Add a Sidebar

The events pages now have a shell, with the footer at the bottom of the window. Inside it, though, the site’s name still sits above the nav, and the seed swap news waits at the end of <main>, below all seven cards.

Rosa wants the header in one row and the news beside Coming Up. In this lesson, you’ll spread the header with flexbox, put a sidebar beside the cards with grid, and decide which tool each box needs and why. Start with the header, which every events page shares.

Spread the Header Across Its Row

The header’s two children, <p class="site-name"> and <nav class="site-nav">, are blocks, so they stack into a sticky header 108 pixels tall. That’s more than the 72 in Line Up Items With Flexbox, because in the grid shell the margins of the name and the list now stay inside the header:

The upcoming events page with Elm Street Community Garden on one line of the header and the Home, Plots, About and Events links on a second line below it.
The Site's Name Stacked Above the Nav

Rosa wants the name on the left and the nav on the right, in one row of two items, each as wide as its text. One direction, sized from the content out, is flexbox’s job. In events/layout.css, find the header rule that made the header sticky, and add two declarations at its end:

Language: CSS
header {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--page);
  display: flex;
  justify-content: space-between;
}

Besides center, justify-content has the value space-between, which puts the first item at the start, the last at the end, and shares the free space out between them.

Save, and the name and the nav share one row:

The upcoming events page with Elm Street Community Garden at the left of the header and the Home, Plots, About and Events links at the right, on the same line, above the events banner.
The Site's Name and the Nav in One Row

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.