All Tutorials  >

Working with Menus

Introduction

In this Tutorial you will work with a basic desktop navigation bar or navbar.

Contents

Introduction

Project folder and files

Overview of navigation menubars

Creating a desktop navbar

About the navbar parent container block

Two child items of the container-menu-desktop block

Working with the desktop navbar menu

Adding more menu options

Styling a link as a CTA button

Changing the colour scheme

Adding a bottom shadow effect

About ‘sticky’ menus

Project folder and files

Your first step is to download the files you need for this Tutorial.

  1. Download the following compressed file to your computer:   menus-sandbox.zip
  2. Copy the ZIP file into your websites folder.
  3. Uncompress the ZIP file.
  4. The files will unzip into a sub-folder of your websites folder named menus-sandbox.   You should see five files: one HTML files, one CSS files and three image files.

Now you can begin to work with the files you have downloaded.

  1. In Visual Studio Code, open the following two downloaded files.
    • menus-sandbox.html
    • menus-sandbox.css
  2. In your web browser, open the menus-sandbox.html web page.

Overview of navigation menubars

On desktop/laptop screens, the main navigation menu is commonly a horizontal bar that stretches left-to-right across the top of the screen. It is commonly called a menubar or navbar. Typically:

In terms of visual appearance, navigation menus can be regarded as of three main types:

Creating a desktop navbar

Follow these steps to create a typical navigation menu or navbar that is displayed on a desktop/laptop screen.

  1. In VS Code, display the menus-sandbox.html web page.
  2. Just after the opening <body> tag, copy-and-paste the following:
    <!-- Begin desktop menu -->
    <nav class="container-menu-desktop menu-dark">
         <!-- first child item -->
         <a href="index.html">
             <img src="menus-logo.png" alt="website logo">
         </a>   
       <!-- second child item -->
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Products</a></li>
            <li><a href="#">Services</a></li>
        </ul>
    </nav>
    <!-- End desktop menu -->
    
  3. Save the menus-sandbox.html web page.

On desktop/laptop screens, the new navbar should look as shown below.

Project Navigation Menus

About the navbar parent container block

Let’s look at the first block that contains the navigation bar for desktop screens. You can see that it has two CSS classes assigned to it.

Project Navigation Menus

The container-menu-desktop CSS class is styled as a flexbox parent container. This sets the content of the navbar, both the logo image and the list of menu options, as centred vertically (top-to-bottom) within the navigation bar. The justify-content: space-between style rule controls the spacing between the logo at the left and list of menu options at the right.

Project Navigation Menus

Two child items of the container-menu-desktop block

Within this ‘parent’ container with its two classes of container-menu-desktop (for layout) and container-menu-dark (for colours) are two ‘child’ items:

Working with the desktop navbar menu

In the next few steps you will update the navbar you created earlier.

First, let’s add two more options to the navbar menu.

  1. To the list of bullet items, add two more menu options as follows. Project Navigation Menus
  2. Save the menus-sandbox.html web page.

In your web browser, the navbar should now look as shown below.

Project Navigation Menus

Next, style the final menu option hyperlink as a button.

  1. To the final option in the list, add a CSS class named btn-cta. This will style the menu option as a button with a solid, coloured background and square corners. Project Navigation Menus
  2. Save the menus-sandbox.html web page.

In your web browser, the navbar should now look as shown below.

Project Navigation Menus

You can reverse the navbar colour scheme simply by changing a CSS class.

  1. Edit the second of the two CSS classes assigned to the container-menu-desktop as shown below. Project Navigation Menus
  2. Save the menus-sandbox.html web page.

In your web browser, the navbar should now look as shown below.

Project Navigation Menus

Now, you will add an extra visual feature: a small shadow effect that is displayed along the bottom of the navigation menu bar.

  1. Add the following third CSS class to the container-menu-desktop as shown below. Project Navigation Menus
  2. Save the menus-sandbox.html web page.

In your web browser, the navbar should now look as shown below.

Project Navigation Menus