Header Component Layout

In this lesson, we will create a header component with skip links.

Creating a menu markup

Once we are ready with the layout, we can identify a couple of components that are easy to design without breaking them up further.

The first component that is easy enough to create is the main menu. We will use skip links to go to different sections of the layout. A skip link is an anchor having an href attribute pointing at a node with an id attribute.

The menu looks as follows:

      <h2 class="header-title">Flexbox Blog</h2>
      <nav class="header-navigation">
        <a href="#home" class="nav-link">Home</a>
        <a href="#posts" class="nav-link">Blog</a> 
        <a href="#contact" class="nav-link">Contact</a>

Let’s add the corresponding id attributes to the body, blogposts container, and the contact container. If this page was a real website, the skip links would work fine. However, in the editor below, the skip links may not be functional. We will just focus on writing the menu style, and ignore the fallback implementation of automatic scrolling.

Positioning the menu with Flexbox

We can identify the need for two Flexboxes to position the menu and the title.

First, we need to position the title and the nav next to each other by making the header node a Flex container.

header {
  padding-top: 20px;
  display: flex;
  justify-content: space-between;

.header-title {
  margin-left: 20px;

Second, we need to play around with the spacing between the individual menu items by making the nav node a Flex container.

.header-navigation {
  display: flex;
  justify-content: flex-end;

.nav-link {
  margin-right: 20px;

After all the changes are performed, the page looks as follows:

Get hands-on with 1200+ tech skills courses.