One of the common challenges when designing responsive design for mobile is the navigation menu. If the site has many sections or pages, it gets challenging to squeeze all the items into a small mobile resolution. The navigation most likely ends up running into multiple lines or the buttons stacking on top each other. So I'm going to review some of the design solution and provide a quick tutorial on how to create a mobile navigation with jQuery.
Problem
The screenshots below show the navigation layout issues on mobile. If the navigation has 3 or 4 buttons like Web Designer Wall, then the navigation won't wrap into two lines. But if the navigation contains 6 or more buttons, they will stack on top each other.

Solutions
1) Dropdown
One of the commonly used solution is to convert the navigation into a select dropdown. I'm not a big fan of this approach because the <select> element is not stylable with CSS. Javascript plugins like Chosen enables you to modify the dropdown menu, otherwise you end up with the default system dropdown styles. It also causes inconsistent user experience where the desktop version displays link tags and the mobile version displays as a dropdown menu. If you like this solution, here is a tutorial by CSS-Tricks on how to convert a menu to a dropdown.


2) Display as Block
Another quick fix is set each menu item as block elements so they display vertically. But this approach takes a lot of header space. If the navigation has many buttons, this is a bad idea because the readers have to scroll down through the long list of navigation before reaching the content.



3) Menu Icon
The last solution that I'm going to review is to use a menu icon/button to toggle the navigation. I like this method out of the three because it saves space (very important on mobile) and it gives you full control of styling with CSS. The menu icon can be styled to match with the overall design.




Mobile Navigation with jQuery (view demo)
This tutorial shows you how to create a mobile navigation with jQuery as seen on the sites listed above. jQuery will be used to prepend the menu icon and toggle the navigation. This trick doesn't require any extra/un-semantic HTML tags.
HTML
Below is the sample navigation HTML used in this tutorial:
<nav id="nav-wrap">
<ul id="nav">
<li><a href="#">Button</a></li>
<li><a href="#">Button</a></li>
</ul>
</nav>
jQuery Code
Include a copy of jQuery and the function below in between the <head> tag. The function will prepend the <div id="menu-icon"> in the <nav id="#nav-wrap"> tag. When the #menu-icon element is clicked, it will slide down the navigation.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
/* prepend menu icon */
$('#nav-wrap').prepend('<div id="menu-icon">Menu</div>');
/* toggle nav */
$("#menu-icon").on("click", function(){
$("#nav").slideToggle();
$(this).toggleClass("active");
});
});
</script>
It will render the HTML code like this (you need to Inspect Element or view generated source code to see this):
<nav id="nav-wrap">
<div id="menu-icon">Menu</div>
<ul id="nav">
<li><a href="#">Button</a></li>
<li><a href="#">Button</a></li>
</ul>
</nav>
CSS
I'm not going to explain every detail of the CSS code because it is pretty straight forward. Instead, I will talk about the key parts.
The #menu-icon is set to display:none initially. I used media query to change the #menu-icon to display:block if the viewport width is smaller than 600px.

In the media query, I set the navigation to display:none so it is hidden initially on mobile. When the #menu-icon is clicked, it will toggle the navigation as specified in the jQuery function at the above step.
Final Demo
To see the final mobile navigation, view the demo and narrow your browser window or check with your mobile phone.

Update:
Also read this CSS Based Responsive Navigation Menu tutorial.
Using the jquery solution in my bones wordpress setup. So far, I get it working pretty well, but I seem to encounter a bug where if you resume a desktop browser width after scaling down and activating the menu at mobile width, the drop down sub menus no longer work on the desktop version. Probably CSS inheritance afoul somewhere given the boilerplate integrating several styles as a default, but I’ve spent hours trying to track it down w/ Chrome dev. tools. Anyone have any experience with this? Likely that ‘users’ won’t be scaling the viewport back and forth, but it would be nice to get this working as well as it does in the demo.
If I’m understanding your problem correctly, you’re saying that if you:
> collapse the menu
> open and close the menu
> expand back to desktop view
Then the nav disappears? If this is the case, you need to specify to display the unordered list again. If you have a breakpoint where you set the list to display: none; you’ll need to make a breakpoint one pixel higher set to display: block !important;
Great, thanks for the article and the tip, easy and to the point. I have implemented the menu on one of my sites.
If I click on the menu in mobile mode, it does drop down the menu. But clicking on anything in the menu didn’t slide the menu up.
I wrote some newbie code for each li. Just wondering if I’m missing something.
function slide() {
if(jQuery(document).width()<=600){
$("#nav").slideToggle();
}
Thanks,
L F
Great tutorial!
Nice work. I like the way you have explained every thing. :)
Is it OK to use this to create a menu in a template I sell?
thanks for the useful info, i am new to responsive design so any other tips would be appreciated.
thanks
Hi..
This has been a huge help for myself and my team members! We needed comprehensive help and direction to finish project on time. Hopefully with all the resources you gave we can get it done!
Thanks a million!.
Thx very much , very easy to understand , it has helped a new born (to web mobile) like me.
Thank you so much. I’ve been looking for this for days and here it is. All I needed was a simple menu and everything I found was super-complex ones.
Really, thank you very much.
Thank you for the tutorial and the great inspiration.
Hello!,,,
I like your preferred method of displaying the navigation as a drop-down. Great tutorial! Thanks for sharing!
i guess we can do with plugins too in wordpress.
Do you have the source code available for this?
Hey,
Excellent post. Mobile navigation is one of the important thing which we need for our website. :)
Thanks
Just what i was looking for, thanks.
I think navigation on mobiles was not that easy, right?
But in this tutorial, it was cool and really impressive to know some helpful guidelines for navigation.
Cool, Thanks for the tutorial.
Very good information on mobile web design and its implementation. Thank you
I know there are a lot of positive comments and kudos already, but I had to give a shoutout to say that I found this tutorial to be very well written and very timely material. Thank you!
This page is awesome! I have been looking around for something like this for a while now. I plan on implementing the third option (toggled menu button) on my site when I redesign shortly. Thanks for the help!