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.
Thank you so much for this! It’s exactly what I was looking for and it worked like a dream.
Hi !
Yeah, you are right. the menu icon is most suitable. But dropdown is not a bad one. Well I actually enjoyed this post. Hope this would be helpful for me.
Thanks.
Brian
One of my favorite mobile solutions, great thing about this piece of code is the fact you get a default style & simply add a query for mobile instead of overwriting the default for mobile.
Mike,
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
@media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
Hi,
Thanks for at great site. I have really learned alot since discovering your site :-)
However this mobile menu does not seems to work in IE8… Not even your demo page.. Anybody else have the same problem?
regards,
Christian.
Firstly let me thank you for this tutorial I have found it very helpful for the most part. That said, I am having an issue with the menu-icon element. I cannot get that icon you have on yours to appear on my version. I thought I might have to download an icon font so I have done this but it is still not functioning as I would have expected. Can you maybe suggest why this might be?
Kind Regards
nice collection!!! φωτοβολταικα
Very useful and informative post. Thank you. φωτογραφιεσ γαμου
Thank you so much for this list! Εκπαιδευση σκυλων Θεσσαλονικη
That’s a really great tutorial! What I didn’t understand so far, is whether you would allow to apply your script within a commercial website in order implement a mobile menu. If yes, do you want to be mentioned and linked in a certain way like it is usual with some CC licences?
Thanks – Danke,
… ist genau das was ich gesucht habe mit einer verständlicheb demo
first of all, great tutorial!!!!! i need some help; I put the navigation along the side, and change the first media query to 7688px; but, the navigation shows. How can I resolve this?
correction: 768px;
What’s Going down i am new to this, I stumbled upon this I’ve discovered It
positively helpful and it has aided me out loads. I’m hoping to give a contribution & aid different users like its aided me. Great job.
Sorry about the last comment. it works now. How do you restrict the page width when in portrait mode?
in the appropriate media query, under the appropriate section; just put “width: ???%” in percents.