Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
ITGeared
  • Social Media
    • Social Media Submenu
      Instagram
      Snapchat
      Facebook
      Reddit
      TikTok
      Twitter
      LinkedIn
  • Streaming
    • Streaming Submenu
      Twitch
      Vimeo
      Youtube
  • Messaging
    • Messaging Submenu
      Discord
      FaceTime
      iMessage
      Microsoft Teams
      Messenger
      Skype
      Slack
      Telegram
      WhatsApp
      Zoom
  • Computers & Programming
    • Computers & Programming Submenu
      Web Development
      Web Building
      HTML / XHTML
      HTML5
      CSS
      CSS3
      Frontend Development
      JavaScript
      AJAX
      jQuery
      Backend Development
      SQL
      ASP
      ADO
      ASP.NET
      Computers & Networking
      VBScript
      Basic Networking
      Windows
      Windows Server
  • Social Media
    • Instagram
    • Snapchat
    • Facebook
    • Reddit
    • TikTok
    • Twitter
    • LinkedIn
  • Messaging
    • Telegram
  • Streaming
    • Twitch
    • Vimeo
    • YouTube
  • Computers & Programming
    • Backend Development
      • SQL
      • ASP
      • ASP.NET
      • ADO
    • Computers & Networking
      • VBScript
      • Basic Networking
      • Windows
      • Windows Server
    • Frontend Development
      • JavaScript
      • jQuery
      • AJAX
    • Web Development
      • Web Building
      • HTML5
      • CSS3
      • HTML/XHTML
      • CSS
ITGeared
  • Social Media
    • Instagram
    • Snapchat
    • Facebook
    • Reddit
    • TikTok
    • Twitter
    • LinkedIn
  • Messaging
    • Telegram
  • Streaming
    • Twitch
    • Vimeo
    • YouTube
  • Computers & Programming
    • Backend Development
      • SQL
      • ASP
      • ASP.NET
      • ADO
    • Computers & Networking
      • VBScript
      • Basic Networking
      • Windows
      • Windows Server
    • Frontend Development
      • JavaScript
      • jQuery
      • AJAX
    • Web Development
      • Web Building
      • HTML5
      • CSS3
      • HTML/XHTML
      • CSS
Computers & Programming​CSS​Web Development

Multi-level Navigation Menu with CSS

Paul BurchBy Paul Burch February 22, 2022February 22, 2022

In this tutorial, we are going to build a mutli-level navigation menu. There are several ways to implement this. In this guide, we are going to build this using HTML and CSS.

If you really want to get fancy and apply some cool effects, you’ll need to apply some JavaScript (or better yet jQuery) techniques.

Navigation Menu HTML Structure

To build our multi-level navigation menu, we are simply going to use an unordered list with sub-lists. Then, we’ll just apply some CSS styling properties to show and hide the second-level items.

<ul id="navMenu">
    <li><a href="#">Home</a></li>
    <li><a href="#">Products</a>
        <ul>
            <li><a href="#">Computers</a></li>
            <li><a href="#">Audio</a></li>
            <li><a href="#">Video</a></li>
        </ul>
    </li>
    <li><a href="#">Contact</a></li>
    <li><a href="#">About</a>
        <ul>
            <li><a href="#">Location</a></li>
            <li><a href="#">Hours of Operation</a></li>
        </ul>
    </li>
</ul>

You can add new second-level sub-items simply by adding new <ul> tags before you end the main item with an <il> tag.

Note in the example above how we started a new unordered list prior to closing the Products main item.

CSS Code

Without CSS, we have a plain multi-level unordered list. We’ll need to apply some creative styles to transform this into a navigation menu. Here is a summary of the CSS code that we will need.

ul#navMenu {
    padding:0px;
    margin:0px;
    width:420px;
    list-style:none;
    position:relative
}

ul#navMenu ul {
    position:absolute;
    left:0;
    top:100%;
    display:none;
    padding:0px;
    margin:0px
}

ul#navMenu li {
    display:inline;
    float:left;
    position:relative
}

ul#navMenu a {
    text-decoration:none;
    padding:10px 0px;
    width:100px;
    background:#666666;
    color:#ffffff;
    float:left;
    text-align:center;
    border:1px solid #ffffff;
}

ul#navMenu a:hover {
    background:#cccccc;
    color:#333333
}

Here is the section of CSS code that makes the sub-items appear when you hover over the first level main items.

ul#navMenu li:hover ul {
    display:block;
}

ul#navMenu ul a {
    width:150px;
}

ul#navMenu ul li {
    display:block;
    margin:0px
}

You first hide the second-level sub-item list by setting the style display:none. Then to make the sub-items appear, you set the style to display:block on the pseudo-class hover on the parent list item.

Third level Menu Items

In this example, we are going to add a third level of menu items. The third level will be placed under the Video sub item.

<ul id="navMenu">
    <li><a href="#">Home</a></li>
    <li><a href="#">Products</a>
        <ul>
            <li><a href="#">Computers</a></li>
            <li><a href="#">Audio</a></li>
            <li><a href="#">Video »</a>
                <ul>
                    <li><a href="#">VCR</a></li>
                    <li><a href="#">DVD</a></li>
                </ul>
            </li>
        </ul>
    </li>
    <li><a href="#">Contact</a></li>
    <li><a href="#">About</a>
        <ul>
            <li><a href="#">Location</a></li>
            <li><a href="#">Hours of Operation</a></li>
        </ul>
    </li>
</ul>

For the third level, we need to add the following CSS styles.

ul#navMenu ul ul {
    top:0;
    left:100%;
}

ul#navMenu li:hover ul ul {
    display:none;
}

ul#navMenu ul li:hover ul {
    display:block;
}

You can continue to create additional levels if needed by following the same pattern of hiding and showing on the hover pseudo-class.

Once you have built a few menu navigation bars, the concept of formatting an unordered list into a menu tab becomes easier and easier. Once you master this technique, you can perform more advanced effects with the help of JavaScript.

Related Posts

Displaying A Gif During Iframe Loading Using Vanilla Javascript

Displaying a GIF During IFRAME Loading Using Vanilla JavaScript

February 9, 2022 February 15, 2022
Active Directory Site Link Costs

Active Directory Site Link Costs

February 10, 2022 February 10, 2022
Stored Procedure Parameters

Stored Procedure Parameters

February 11, 2022 February 11, 2022
Introducing Windows Server 2012

Introducing Windows Server 2012

February 11, 2022 May 17, 2022
Asp Conditional Statements

ASP Conditional Statements

February 17, 2022 February 17, 2022
Choosing A Domain Name For Your Active Directory

Choosing a Domain Name for your Active Directory

February 23, 2022 February 23, 2022

About The Author

Paul Burch

Paul Burch

Paul is a programming enthusiast who loves to write about all things technical. Whether it's networking, operating systems or programming, Paul enjoys delving into the nuts and bolts of technology and explaining it in a way that everyone can understand. When he's not writing articles for ITGeared.com, Paul likes to spend his time tinkering with computers and playing video games.

Leave a Comment Cancel Reply

Your email address will not be published. Required fields are marked *

Paul Burch
Paul BurchAuthor

Paul is a passionate programmer who enjoys writing about all things technical. He likes getting into the nitty-gritty of technology and describing it in a way that anybody can understand.

Latest Posts
What Is Synacor Youtube Tv
What Is Synacor YouTube TV?
October 16, 2023
Why Did Apbassing Quit Youtube
Why Did Apbassing Quit YouTube?
October 16, 2023
How To Upload Mp3 To Youtube
How To Upload MP3 to YouTube
October 16, 2023
Related Posts
Mysql Date_Sub Function
MySQL DATE_SUB Function
February 16, 2022
Enabling And Disabling Proxy Settings Via Shortcut
Enabling and Disabling Proxy Settings via Shortcut
June 15, 2022
What Is Fsmo?
What is FSMO?
May 18, 2022

Categories

  • Social Media
  • Messaging
  • Computers & Programming
  • Streaming

About

  • About Us
  • Privacy Policy

Copyright © 2021 - 2025 - ITGeared

Scroll to Top