How To Create A Google Like Drop Down Navigation Menu With CSS? (No JavaScript)


We all do visit google.com page hundreds times in a day, may be more than that to find anything on web. You must be aware of new design changes throughout all google products. The main attraction of these changes is the black colored top navigatio

n bar, which consists links like “+You”, “Web”, “Images”, “Photos” etc.

In this tutorial, I wil help you to create a black colored top navigation menu like you see on google’s home page. I got few requests from you readers which encouraged me to design it for you. Let’s see what we are going to design in the screen shot below:
Google like black colored top navigation menu with drop down

Step 1: CSS Styling

body {
	margin:0 auto;
}

/*--navigation wrapper--*/
#navwrapper {
	margin:0 auto; 
	background-color: #2D2D2D;
}


#nav {
	font-family: Arial, Helvetica, sans-serif;
	font-size:12px; 
	padding-top:4px;
}

#nav, #nav ul {
	padding: 0;
	margin: 0;
	list-style: none;
	font-family: Arial, Helvetica, sans-serif;
}

/*--main nav links style--*/
#nav a {
	display:block;
	padding:7px 7px 7px 7px; 
	color:#ccc; 
	text-decoration:none;
}

#nav a.dmenu {

}

#nav a.dmenu:hover {
	color:#3366CC !important;
	background-color: #fff !important;
}

#nav li {
	float: left;
}

#nav li {position: relative;}

/* hide from IE, mac */
#nav li {position: static; width: auto;}
/* end hiding from IE5 mac */

/*--drop down menu styling--*/
#nav li ul {
	position: absolute;
	display: none;
	margin-left:-1px;
	padding-bottom:10px;
	background-color: #FFFFFF;
	border: 1px solid #bbb;
	border-top:none;
	-moz-box-shadow: 0 0 5px #ddd;
	-webkit-box-shadow: 0 0 5px #ddd;
	box-shadow: 0 0 5px #ddd;
	/*--make it top of all the elements on page, so that it can be visible--*/
	z-index:5000; 
}

#nav li:hover a, #nav a:focus,
#nav a:active {
	padding:7px 7px 7px 7px;		
	color:#fff; 
	background:#444; 
	text-decoration:none; 
}

#nav li ul, #nav ul li  {
	width: 10em;
}

/*--drop down menu styling is different from main nav, strict rule--*/
#nav ul li a  {
	color: #3366CC !important;
	border-right: 0;
}
#nav ul li a:hover  {
	color:#3366CC !important;
	background-color: #eef3fb !important;
	border-right: 0;
}

/*--the selected, current item in the navigation menu--*/
#nav a.current{
	color:#fff;
	font-weight:bold; 
	background:#2D2D2D; 
	text-decoration:none; 
	border-top:2px solid #C33;
	padding-bottom:5px; /*--removing 2px border from 7px padding--*/
}

#nav a.current:hover{
	padding-bottom:5px; /*--removing 2px border from 7px padding--*/
}

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

#nav li:hover ul a{
	color: #000000;
	background-color: transparent;
}

#nav ul a:hover {
	background-color: #606060!important;
	color: #FFFFFF !important;
}

 /*--used in drop down menu items--*/
.menuseprator{border-bottom:1px solid #ddd; margin:10px 0 10px 0;}

/*--for showing down arrow in drop down menu item--*/
.arrowdown{color#eee; font-size:0.5em;}  

/*--for the left navigation menu--*/
.floatleft{float:left;} 

/*--for the right options navigation menu--*/
.floatright{float:right;}

/*--clear all floating, left and right--*/
.clear{clear:both;} 

Step 2: HTML Markup


That’s it, just copy and paste the CSS and HTML code from above and you are done! You can see a live preview on the following link.

Live Demo

You can also checkout our previous post on “How to create google like top navigation?” (white color)

Tested and works with all popular browsers, IE7, IE8, IE9, Safari 4+, Opera 9+, FF 3+, Chrome 8+. Please drop me message in the comments below, if you see issue with any browser. Suggestions and feedback are always welcome to improve.

Related posts:

About Sach

Sachin is a web application developer, technology blogger and web addict! He has over 6 years of web development experience and he writes tutorials primarily focused on LAMP, Ajax, Api's, jQuery etc. He is usability expert and he always likes to share his knowledge with people.
  • Dominicanstan

    Thanks a lot!

    But on line 94. background:#000000;
    is not #000000 is #2D2D2D
    background:#2D2D2D

    Thanks again!

    • SachinKRaj

      Dominicanstan: Thanks a lot for the correction, I have updated the code and the demo files.

  • DeLu

    Hey! I love the menu you’ve managed to reproduce. Althought I have a question. Do you have any idea why it won’t show buttons in both left and right side? I use up-to-date Google Chrome browser and still all of my buttons from your menu are alligned in the left side while in ur demo they are split in left and right side. you can have a look at my website which is found here http://www.guesswhatshere.com/ all I did is copy paste html+css without touching them or editing anything. please reply. I dont wanna use this menu unless it’ll show buttons in both sides. thank you very much. best regards, chris :)

    • SachinKRaj

      Hey Delu,

      I didn’t get you, could you please explain a bit more? What kind of buttons you are looking for? I didn’t add any buttons in the menu.

  • DeLu

    Hello. Thanks for you reply, althought my issues are now solved. I had a lil trouble with the buttons floating. They were all floating in to the left side of the screen instead of both right and left side. Thanks again tho. Regards, Chris.

    • SachinKRaj

      Yeah, I saw it and looks fine to me. Let me know if you need any further assistance. I will be happy to help you.

    • Sophie

      DeLu,

      In the CSS, you need to close the spce between the “h” and “t” in the word “right” }

      Wrong }

      /*–for the right options navigation menu–*/
      128..floatright{float:righ t;}

      This is the correction }

      /*–for the right options navigation menu–*/
      128..floatright{float:right;}

      When you do this, the words gmail, setting & logout will move to the right of the page :)

  • DeLu

    Hehe thanks dude! You are too kind! WIll gladly ask you if Ill ever need help:D gz on the menu btw! Farewell!

    • SachinKRaj

      Thanks Friend.

  • chatroulette

    Thank you! Just what we need! Replacing old one soon …

  • Shobz

    Very Nice :D hey but google has again changed the menu now…. can you please share that one too… its really nice black menu under the logo….

    • SachinKRaj

      Thanks!
      Sure, will be coming soon :)

  • Princa

    Nice job! I am trying to modify a little bit of the sub navigation system. If I want to put a sub navigation system under top-right portion, say under “Settings” when hover show more options, like google’s profile button, the sub navigator is a big box with lots of contents but it aligns to right instead of left. do you know how to implement it?

    • Princa

      use right: x;

  • Princa

    If i have more than 2 menus need sub nav, and each sub nav align with each menu’s right edge…how to do that dynamically? I mean not manually setup right:xx px;

  • Curtis

    Thanks for sharing this tutorial and code. If you sign in to Google and look at how they treat the account panel and notifications, how would I go about adding those two components in the bar?

    • SachinKRaj

      Curtis: I will release code for the same in new article by the next week.

  • DeLu

    Dude, I’m back with another question for you. I’m sorry for the offtopic, since my issue isn’t related to this topic, but you are the only person I can ask at the moment, a person which I guess has the knowledge. Anyway, @ my website ( http://www.guesswhatshere.com ) I’m trying to put a facebook like box for my potential fans. And as you can see, I’ve managed to do it but as you can see…my website header is fixed..and when I try to scroll down to the bottom of the page..nothing goes over my fixed header, except the facebook like box. you can have a look. can you please tell me what should I do? I’m stuck at the moment, really. hopefully you’ll have a minute to reply and mby I can solve this problem:D The codes facebook gave me are:
    (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = “//connect.facebook.net/en_US/all.js#xfbml=1&appId=180833238638056″;
    fjs.parentNode.insertBefore(js, fjs);
    }(document, ‘script’, ‘facebook-jssdk’));
    as the script and:

    as the like box.
    Thank you in advance. regards, Chris.

    • SachinKRaj

      Try iframe based facebook like box code. The current code CSS is inherting to the main CSS. Z-index from the fb style class “fb_iframe_widget” is getting inherited over your site’s CSS.
      Try adding more valued z-index to the main header class.

  • Luiz Felipe S. C.

    Hi, thanks for this post, can um help me? I´m trying put this topbar in wordpress. Where i put the css code? I need to create a new css file? I paste all this on header.php?

    • SachinKRaj

      Luiz, You can put the CSS at the end of the WordPress theme’s style sheet. Let me know the link of your wordpress site. I will surely help you.

  • he

    It’s cool, but what about nowrap??

  • Ameer

    I need the sub-menu to collapse when clicked, not hovered. How do I do that?

  • Trevor

    There is a typo in your posted CSS:

    /*–for the right options navigation menu–*/
    .floatright{float:rightright}

    • SachinKRaj

      Thanks friend. Its fixed. :)

    • SachinKRaj

      I dont know the code highlighting plugin is behaving odd so I had to put space between the word right.

  • Ravi

    hello bro i think here bit mistake
    in last of HTML Markup
    in line 34

    use / in this line

    • SachinKRaj

      Ravi, Thanks for the edit. Its fixed now.

      • Ravi

        dear
        drop down menu all in center how to shift them in left side

        • SachinKRaj

          Just apply the class “dmenu” in any of the li element.

      • Ravi

        dear
        drop down menu all in center how to shift them in left side
        check my website

        http://www.googlegenius.in

        • SachinKRaj

          Ravi, I can see the menu is coming perfectly. Could you please let me know how do you want it to be?

  • Ravi

    Last of HTML Markup
    in line 34

    use / in this line

  • Deepak

    Thanks a lot for this article! a real help ’twas.

    • SachinKRaj

      Thanks a ton Deepak for appreciating :)

  • Sophie

    For @gmail, settings and logout to align right on the menu bar, fix this error in CSS }

    /*–for the right options navigation menu–*/
    128..floatright{float:righ t;}

    * {float: righ t;} should be {float: right;}

    • SachinKRaj

      Thanks Sophie, its fixed. My code highlighter plugin was creating issue with showing css code. Anyways, I worked around it and the code is fine now. Please check.

      • Sophie

        This is a great piece of work.  It looks great SachinKRaj :)  I was wondering…how would you add a drop shadow under the navbar?

        • Sachin Kumar Rajput

          Thanks Sophie.
          A drop shadow can be added to an element with the box-shadow property of css3:

          -moz-box-shadow: 0 0 5px #ddd;
          -webkit-box-shadow: 0 0 5px #ddd;
          box-shadow: 0 0 5px #ddd;

          • Sophie

            Thank you :)   What element do I attach this to?

          • Sachin Kumar Rajput

            You can apply to the menu wrapper, the subanv element

            ul li ul{ }

            like this

            ul li ul{
            -moz-box-shadow: 0 0 5px #ddd;
            -webkit-box-shadow: 0 0 5px #ddd;
            box-shadow: 0 0 5px #ddd;
            ………
            ……..
            }

  • Muhaimin Abdul

    is there any idea make the drop down profile box at google search

    • Sachin Kumar Rajput

      @facebook-715727098:disqus You can change in dmenu class and have it in large width.

  • Topmse

    i am going to try this at my new search engine.
    http://search.topmse.com/

    thanks for the post.

    • Sachin Kumar Rajput

      Ok Great!

  • Dominik

    #nav li:hover a.dmenu { 
      color:#3366CC !important; 
      background-color: #FFFFFF !important; 
    }      

    add this if you want the dropdown-button to remain white while the dropdown is open (like its on google!).

    great css! thank you very much!

    • Sachin Kumar Rajput

      @Dominik: Thanks :)

  • Maxwhite2012

    How do I go about making this centered? I see the clear, however where do I place it? Thanks a heap in advance.

    • Sachin Kumar Rajput

      Try setting margin as: margin:0 auto 0 auto;

      You can have different values in place of zero.

      • Maxwhite2012

        My website that I’m using this on is http://etherspider.com

        I tried your suggestion and nothing.

        Thanks for your replies!

        • Sachin Kumar Rajput

          Could you please share more info? I can’t see the menu on the link you shared?

  • guest

    Thanks for the post. However IE9 doesnt display it correctly. Any suggestions? here is a snapshot:

    • Sachin Kumar Rajput

      It is coming fine at my end, I have just checked it on different machines too. Could you please share your code so that I can help you to fix it?

  • Andy Boy

    Hey Sachin,

    Thanks for the tut on the google bar. I have just noticed that Google have changed their drop down menu to black font and also when you click on it it stays open. Is it possible to look into this perhaps please? ^^

    Andy Boy

  • chiljane

    ha ha ha nice copy and paste work.

    • Sachin Kumar Rajput

      Thanks. This copy paste work helped few people and I am glad to know that too.. :)

  • Kingdom Crusade

    Great! Thank you! The code made my day! Because my theme supports only one menu. You’ve made a great help for me!

    And it would be greater if someone help me make the menu fixed and visible on top even while scrolling down.

    Thanks again!