Lesson 2: Stylizing a Navigation Menu with CSS


In the previous lesson, you learned about controlling the layout of a web page using CSS. One of the techniques you learned was floating content so that elements appear beside one another. In the current lesson you will apply these techniques to stylizing your navigation menu.

Learner Outcomes

At the completion of this exercise:


  1. Open your portfolio's external style sheet in a text editor, and your portfolio home page in a browser. After each step listed below, save your style sheet, then refresh your page in the browser to see what effect the change has had.
  2. In your external style sheet, create a new section at the end of your CSS file to keep all the styles related to the navigation menu together. You can do this by adding a comment to the end of the file, like this:
      /* navigation menu styles */
    Then, all styles related to the navigation menu will go after this comment. NOTE: Each of the style definitions that follow is unique. The selectors are similar, but if you look closely at them you'll see that they actually refer to distinct elements. So be sure to include each of these definitions in your style sheet.
  3. The navigation menu is contained within the nav element, but that's just a container. Most of the elements we need to stylize are actually contained inside the nav element. To stylize them, we can use descendant selectors, which were defined in the lesson on id and class. To start with, we can remove the bullets from the unordered list, like this:
    nav ul { 
      list-style-type: none;
  4. Next, float all list items to the left, just like you did with the .info divs in the previous lesson. While you're at it, you might want to add a margin to the right of each list item so they're not all squished together:
    nav ul li { 
      float: left;
      margin-right: 0.5em;
  5. Next stylize the anchors (links) that are nested inside the list items. The style you add here makes the list items look like menu buttons. The following styles are an example, but feel free to tweak these styles and come up with your own unique menu style:
    nav ul li a { 
      padding: 0.25em 1em;
      text-decoration: none; /* no underline */
      background-color: #EBF5FF; /* pale bluish white */
      color: #4312AE; /* dark blue */
      border: 2px solid black;
      border-top-left-radius: 1em 1em; /* rounded corner! */
      border-top-right-radius: 1em 1em; /* another rounded corner! */	 
  6. Now add :hover and :focus pseudo-classes so the menu items change color when users point or tab to them:
    nav ul li a:hover, nav ul li a:focus { 
      color: black; 
      background-color: white; 
      font-weight: bold;
  7. You might also need to adjust the style of the nav itself to make the menu fit better, but that's up to you.
  8. Finally, to prevent side effects from all those floated elements, add clear:left to the style definition for main, since that's the content that immediately follows the navigation menu.

Handouts/Online Documents

All done?

Save your changes, and show your final navigation menu to your instructor before starting the next module.