The following files are required for this lesson:

Introduction

This lesson will be taught in three stages:

Demo Instructions

You can follow along with your instructor to complete this build and/or you can use this document as a guide in completing the demo build.

Steps – Stage 1: Basic Toggle Nav

  1. Download the demo-toggle-nav.zip file and extract its contents to a folder named demo-toggle-nav.
  2. The completed output should look like when you resize your browser:
    toggle1-01.jpgtoggle1-02.jpg
    Note: When the browser is resized, the menu will start to wrap to the next row.
  3. Add the following code to your index.html:
    1. Add the <header> block:
      toggle1-index-01
    2. Add the <section> block:
      toggle1-index-02
    3. Add the following code, which must the last line of code in the <body>:
      toggle1-index-03
      Open index.html in the browser to see:
      toggle1-03
      Question: What needs to be done now?
  4. Open styles.css and add the following:
    1. You will need a .flex-container class:
      toggle1-css-styles-01
    2. Start styling the header and nav:
      toggle1-css-styles-02
    3. Add styling for the menu and hover effects:
      toggle1-css-styles-03
    4. Style the toggle button:
      toggle1-css-styles-04
    5. Style the menu list items:
      toggle1-css-styles-05
    6. Refresh your browser to see:
      toggle1-04
      Note: The hamburger icon does not collapse the menu; it is still fixed in place.
      Question: What is the next step?
  5. The next step is to hide the menu. Add the following rules to your styles.css:
    1. Style the header nav:
      toggle1-css-styles-06
    2. Create a class that will show the menu:
      toggle1-css-styles-07
      Refresh your browser to see (press the hamburger icon to see the changes):
      toggle1-05
      Question: What is the next step?
  6. Next the <section> needs some styling so add the following style rules:
    1. Initial section styling:
      toggle1-css-styles-08
    2. Style the paragraph:
      toggle1-css-styles-09
    3. Style the heading:
      toggle1-css-styles-10
      Refresh your browser to see (you will need to resize your browser):
      toggle1-06
      Question: What needs to be done next?
  7. A media query is needed, thus add the following media query:
    1. Hide the toggle button (hamburger icon):
      toggle1-css-styles-11
    2. Show the nav by default, thus add the following to your media query:
      toggle1-css-styles-12
  8. The result, at a wider browser width, is:
    toggle1-07.jpg
    Question: When the toggle button is pressed, the section content is pushed down. Would it not be better if the dropdown menu were an overlayed menu?

Steps – Stage 2: Toggle Nav Version 2

  1. To get the desired effect make the following changes to your styles.css file:
    1. Modify the header nav style rule as shown below:
      toggle2-css-styles-01
    2. Add some padding to the menu (add this below the header nav style rule):
      toggle2-css-styles-02
  2. Refresh your browser to see the menu now overlays the section content.
    toggle2-01.jpg

Steps – Stage 3: Toggle Nav Version 3

  1. Download the toggle-nav-3-images.zip file from Moodle and extract the images to your img folder.
  2. The completed output should look like (partial view shown):
    toggle3-01.jpg
  3. The first step is to add the following to your index.html:
    1. Add the following below the <h2> in the <section>:
      toggle3-01
      You should see the images below the heading. </ol>
  4. Now add the following style rules below the section h2 style rule:
    1. Style the .gallery class:
      toggle3-css-styles-01
    2. Style the .thumbnail class:
      toggle3-css-styles-02
    3. Style the <span> class:
      toggle3-css-styles-03
  5. Test the results in your browser; use different browser widths to see the full effects.

Module Home

DMIT1530 Home