How to Create a Drop-Down Nav Menu With HTML5, CSS3 and JQuery

In this tutorial, we’ll take a look and see what we can achieve with HTML5 and CSS3 when it comes to a staple of current web sites: the humble drop-down navigation menu. We’ll also use jQuery to handle the effects and add the finishing touches for us.

HTML5 brings to the spec a dedicated <nav> element that should be used as the container for any major navigation structure, such as the main vertical or horizontal site navigation menus, or an in-page table of contents for example.

Using these new features, we’ll build a drop-down navigation menu with clean and semantic HTML code. 

Here’s what we’ll be building:

Let’s get started.

1. Getting Started

We’ll need a copy of the latest release of jQuery, version 3.6.0 at the time of writing.

Create a project folder for the files we’ll create somewhere on your machine and call it dropdown-web, inside this folder create three new folders; one called index.html for the HTML markup, one called style.css for the styling and one called script.js for the scripting with jQuery. 

2. Create The Underlying Page

Begin by importing jQuery and Font Awesome into the HTML head tags:

 Next, we code the HTML markup for the nav menu inside of index.html. You can use any code editor of your choice:

Using the HTML5 <header> tag, we create a header containing two sections—the logo section and the navigation menu. The navigation menu contains a list of navigations. Each navigation group has a link, an icon from Font Awesome and a <div> containing four sub nav links. These nav links will be displayed in the dropdown menu.

We assign class attributes to most of the tags, this will enable us to access them in our stylesheet and jQuery script later on. Finally, below the markup, we use a <script> tag to load our script from the file script.js.

3. Add CSS

Now let’s add some basic styling; create the following stylesheet inside style.css:

We began by resetting padding and margin for all elements to 0px, and setting a typeface for our HTML document.

The .navActive class will be toggled onto whichever navigation item the user hovers his mouse on, this will in turn toggle the nav link items in the dropdown below the main text.

This feature will be implemented in the following scripts section using jQuery.

4. Add the Script

The script for toggling each navigation is very simple:

In the script, we’re saying that whenever any of elements with a class of nav-1, nav-2, nav-3, or nav-4 is hovered upon, we want to display its items inside a dropdown menu by toggling the navActive class on the element.

Recall that in our stylesheet, we hid the dropdown elements by default:

When any of those elements are hovered upon, the jQuery script will toggle this class on the said element:

As a result, the div element and all of its children will go from hidden display to flex display.

Final Thoughts

I hope this tutorial helped you understand HTML5 and CSS better. In the process of building this dropdown navigation  menu, we covered some basic CSS selectors and a couple of HTML tags to help you structure and design your web pages.


This content originally appeared on Envato Tuts+ Tutorials and was authored by Kingsley Ubah

In this tutorial, we’ll take a look and see what we can achieve with HTML5 and CSS3 when it comes to a staple of current web sites: the humble drop-down navigation menu. We’ll also use jQuery to handle the effects and add the finishing touches for us.

HTML5 brings to the spec a dedicated <nav> element that should be used as the container for any major navigation structure, such as the main vertical or horizontal site navigation menus, or an in-page table of contents for example.

Using these new features, we'll build a drop-down navigation menu with clean and semantic HTML code. 

Here's what we'll be building:

Let's get started.

1. Getting Started

We’ll need a copy of the latest release of jQuery, version 3.6.0 at the time of writing.

Create a project folder for the files we’ll create somewhere on your machine and call it dropdown-web, inside this folder create three new folders; one called index.html for the HTML markup, one called style.css for the styling and one called script.js for the scripting with jQuery. 

2. Create The Underlying Page

Begin by importing jQuery and Font Awesome into the HTML head tags:

 Next, we code the HTML markup for the nav menu inside of index.html. You can use any code editor of your choice:

Using the HTML5 <header> tag, we create a header containing two sections—the logo section and the navigation menu. The navigation menu contains a list of navigations. Each navigation group has a link, an icon from Font Awesome and a <div> containing four sub nav links. These nav links will be displayed in the dropdown menu.

We assign class attributes to most of the tags, this will enable us to access them in our stylesheet and jQuery script later on. Finally, below the markup, we use a <script> tag to load our script from the file script.js.

3. Add CSS

Now let’s add some basic styling; create the following stylesheet inside style.css:

We began by resetting padding and margin for all elements to 0px, and setting a typeface for our HTML document.

The .navActive class will be toggled onto whichever navigation item the user hovers his mouse on, this will in turn toggle the nav link items in the dropdown below the main text.

This feature will be implemented in the following scripts section using jQuery.

4. Add the Script

The script for toggling each navigation is very simple:

In the script, we're saying that whenever any of elements with a class of nav-1, nav-2, nav-3, or nav-4 is hovered upon, we want to display its items inside a dropdown menu by toggling the navActive class on the element.

Recall that in our stylesheet, we hid the dropdown elements by default:

When any of those elements are hovered upon, the jQuery script will toggle this class on the said element:

As a result, the div element and all of its children will go from hidden display to flex display.

Final Thoughts

I hope this tutorial helped you understand HTML5 and CSS better. In the process of building this dropdown navigation  menu, we covered some basic CSS selectors and a couple of HTML tags to help you structure and design your web pages.


This content originally appeared on Envato Tuts+ Tutorials and was authored by Kingsley Ubah


Print Share Comment Cite Upload Translate Updates
APA

Kingsley Ubah | Sciencx (2014-01-20T02:31:18+00:00) How to Create a Drop-Down Nav Menu With HTML5, CSS3 and JQuery. Retrieved from https://www.scien.cx/2014/01/20/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/

MLA
" » How to Create a Drop-Down Nav Menu With HTML5, CSS3 and JQuery." Kingsley Ubah | Sciencx - Monday January 20, 2014, https://www.scien.cx/2014/01/20/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/
HARVARD
Kingsley Ubah | Sciencx Monday January 20, 2014 » How to Create a Drop-Down Nav Menu With HTML5, CSS3 and JQuery., viewed ,<https://www.scien.cx/2014/01/20/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/>
VANCOUVER
Kingsley Ubah | Sciencx - » How to Create a Drop-Down Nav Menu With HTML5, CSS3 and JQuery. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2014/01/20/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/
CHICAGO
" » How to Create a Drop-Down Nav Menu With HTML5, CSS3 and JQuery." Kingsley Ubah | Sciencx - Accessed . https://www.scien.cx/2014/01/20/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/
IEEE
" » How to Create a Drop-Down Nav Menu With HTML5, CSS3 and JQuery." Kingsley Ubah | Sciencx [Online]. Available: https://www.scien.cx/2014/01/20/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/. [Accessed: ]
rf:citation
» How to Create a Drop-Down Nav Menu With HTML5, CSS3 and JQuery | Kingsley Ubah | Sciencx | https://www.scien.cx/2014/01/20/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.