You are on page 1of 12

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

Advertise Here

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu


Guillaume Marty on Oct 13th 2010 with 455 Comments and 0 Reactions

Tutorial Details
Topic: HTML / CSS3 Difficulty: Moderate Estimated Completion Time: 30 min

Final Product What You'll Be Creating

This entry is part 16 of 16 in the CSS3 Mastery Session - Show All Previous Often used on e-commerce or large scale websites, mega menus are becoming more and more popular, as they offer an effective solution to displaying a lot of content while keeping a clean layout. In this tutorial, well learn how to build a cross-browser, awesome CSS-only drop-down mega menu, using nice CSS3 features.

Step 1: Building the Navigation Bar


Lets begin with a basic menu, built with an unordered list and some basic CSS styling. view plaincopy to clipboardprint? 1. <ul id="menu"> 2. <li><a href="#">Home</a></li> 3. <li><a href="#">About</a></li> 4. <li><a href="#">Services</a></li> 5. <li><a href="#">Portfolio</a></li> 6. <li><a href="#">Contact</a></li> 7. </ul>

Creating the Menu Container


Well now apply some basic CSS styling. For the menu container, we define a fixed width that we center by setting the left and right margins to auto. view plaincopy to clipboardprint? 1. #menu { 2. list-style:none; 3. width:940px; 4. margin:30px auto 0px auto; 5. height:43px; 6. padding:0px 20px 0px 20px; 7. } Now, lets see how we can improve it with some CSS3 features. We need to use different syntaxes for Webkit-based browsers (like Safari) and for Mozilla-based browsers (like Firefox). For rounded corners, the syntax will be : view plaincopy to clipboardprint? 1. -moz-border-radius: 10px 2. -webkit-border-radius: 10px; 3. border-radius: 10px; For the background, well use gradients and a fallback color for older browsers. To keep consistency when choosing colors, there is an awesome tool called Facade that helps you find lighter and darker tones of a basic color. view plaincopy to clipboardprint? 1. background: #014464; 2. background: -moz-linear-gradient(top, #0272a7, #013953); 3. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0272a7), to(#013953)); The first line applies a simple background color (for older browsers); the second and third lines create a gradient from the top to the bottom using two colors : #0272a7 and #013953. We can now add a darker border and polish the design with a fake inset border created with the box-shadow feature. The syntax is the same for all compatible browsers: the first value is the horizontal offset, the second one is the vertical offset, the third one is the blur radius (a small value makes it sharper; it will be 1 pixel in our example). We set all offsets to 0 so the blur value will create a uniform light border : view plaincopy to clipboardprint? 1. -moz-box-shadow:inset 0px 0px 1px #edf9ff; 2. -webkit-box-shadow:inset 0px 0px 1px #edf9ff; 3. box-shadow:inset 0px 0px 1px #edf9ff; Heres the final CSS code for the #menu container : view plaincopy to clipboardprint? 1. #menu { 2. list-style:none; 3. width:940px; 4. margin:30px auto 0px auto; 5. height:43px; 6. padding:0px 20px 0px 20px; 7. /* Rounded Corners */

1 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. }

-moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; /* Background color and gradients */ background: #014464; background: -moz-linear-gradient(top, #0272a7, #013953); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0272a7), to(#013953)); /* Borders */ border: 1px solid #002232; -moz-box-shadow:inset 0px 0px 1px #edf9ff; -webkit-box-shadow:inset 0px 0px 1px #edf9ff; box-shadow:inset 0px 0px 1px #edf9ff;

Styling Menu Items


We will begin with all menu items aligned to the left and space them with a margin-right (the padding will be necessary for the hover state) : view plaincopy to clipboardprint? 1. #menu li { 2. float:left; 3. display:block; 4. text-align:center; 5. position:relative; 6. padding: 4px 10px 4px 10px; 7. margin-right:30px; 8. margin-top:7px; 9. border:none; 10. } For the hover state and the drop down, I have chosen a grey color scheme for the background. The fallback color will be a light grey (#F4F4F4) and the gradient will be applied from the top (#F4F4F4) to the bottom (#EEEEEE). Rounded corners will be applied only on top corners as well have the drop down sticking right under the menu items. view plaincopy to clipboardprint? 1. background: #F4F4F4; 2. background: -moz-linear-gradient(top, #F4F4F4, #EEEEEE); 3. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#EEEEEE)); The left and right padding is slightly smaller here because we have a border of 1 pixel appearing on hover. If we keep the same padding, menu items will be pushed two pixels on the right because of the left and right borders added on mouse hover. To avoid that, well remove 1 pixel of padding on both sides, so we have 9 pixels instead of 10. view plaincopy to clipboardprint? 1. border: 1px solid #777777; 2. padding: 4px 9px 4px 9px; Then, we add rounded corners to the top only so the drop down will stick perfectly under the parent menu item : view plaincopy to clipboardprint? 1. -moz-border-radius: 5px 5px 0px 0px; 2. -webkit-border-radius: 5px 5px 0px 0px; 3. border-radius: 5px 5px 0px 0px; Here is the final CSS for the menu items on hover : view plaincopy to clipboardprint? 1. #menu li:hover { 2. border: 1px solid #777777; 3. padding: 4px 9px 4px 9px; 4. /* Background color and gradients */ 5. background: #F4F4F4; 6. background: -moz-linear-gradient(top, #F4F4F4, #EEEEEE); 7. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#EEEEEE)); 8. /* Rounded corners */ 9. -moz-border-radius: 5px 5px 0px 0px; 10. -webkit-border-radius: 5px 5px 0px 0px; 11. border-radius: 5px 5px 0px 0px; 12. } For the links, well apply a nice text shadow using a simple syntax : the first and second values are horizontal and vertical offsets for the shadow (1 pixel in our example), the third one is the blur (1 pixel too) and then we have the (black) color : view plaincopy to clipboardprint? 1. text-shadow: 1px 1px 1px #000; Here is the final CSS for the links : view plaincopy to clipboardprint? 1. #menu li a { 2. font-family:Arial, Helvetica, sans-serif; 3. font-size:14px; 4. color: #EEEEEE; 5. display:block; 6. outline:0; 7. text-decoration:none; 8. text-shadow: 1px 1px 1px #000; 9. } On mouse hover, as the background is grey, well use a darker color (#161616) for the links and the white color for the text shadow : view plaincopy to clipboardprint? 1. #menu li:hover a { 2. color:#161616; 3. text-shadow: 1px 1px 1px #FFFFFF; 4. } Finally, we need a way to indicate if theres a drop down or not by using a simple arrow image as background, it will be positioned on the right using padding and the top margin will align to it properly. On hover this top margin will be set to 7 pixels instead of 8 as we have an additional border appearing on mouse hover (otherwise, the arrow would be pushed 1 pixel down on hover) : view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. #menu li .drop { padding-right:21px; background:url("img/drop.png") no-repeat rightright 8px; } #menu li:hover .drop { background:url("img/drop.png") no-repeat rightright 7px; }

Here is our final code for the menu container and links; only the home item doesnt have any drop down content for now : view plaincopy to clipboardprint? 1. <ul id="menu"> 2. <li><a href="#">Home</a></li> 3. <li><a href="#" class="drop">About</a></li> 4. <li><a href="#" class="drop">Services</a></li> 5. <li><a href="#" class="drop">Portfolio</a></li>

2 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

6. <li><a href="#" class="drop">Contact</a></li> 7. </ul> view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. #menu { list-style:none; width:940px; margin:30px auto 0px auto; height:43px; padding:0px 20px 0px 20px; /* Rounded Corners */ -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; /* Background color and gradients */ background: #014464; background: -moz-linear-gradient(top, #0272a7, #013953); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0272a7), to(#013953)); /* Borders */ border: 1px solid #002232; -moz-box-shadow:inset 0px 0px 1px #edf9ff; -webkit-box-shadow:inset 0px 0px 1px #edf9ff; box-shadow:inset 0px 0px 1px #edf9ff; } #menu li { float:left; display:block; text-align:center; position:relative; padding: 4px 10px 4px 10px; margin-right:30px; margin-top:7px; border:none; } #menu li:hover { border: 1px solid #777777; padding: 4px 9px 4px 9px; /* Background color and gradients */ background: #F4F4F4; background: -moz-linear-gradient(top, #F4F4F4, #EEEEEE); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#EEEEEE)); /* Rounded corners */ -moz-border-radius: 5px 5px 0px 0px; -webkit-border-radius: 5px 5px 0px 0px; border-radius: 5px 5px 0px 0px; } #menu li a { font-family:Arial, Helvetica, sans-serif; font-size:14px; color: #EEEEEE; display:block; outline:0; text-decoration:none; text-shadow: 1px 1px 1px #000; } #menu li:hover a { color:#161616; text-shadow: 1px 1px 1px #FFFFFF; } #menu li .drop { padding-right:21px; background:url("img/drop.png") no-repeat rightright 8px; } #menu li:hover .drop { background:url("img/drop.png") no-repeat rightright 7px; }

And the result is :

Step 2: Coding the Drop Down


A classic drop down menu usually contains lists nested within parent list items and looks like: view plaincopy to clipboardprint? 1. <ul id="menu"> 2. <li><a href="#">Item 1</a>< 3. <ul> 4. <li><a href="#">Subitem 1</a></li> 5. <li><a href="#">Subitem 2</a></li> 6. <li><a href="#">Subitem 3</a></li> 7. </ul> 8. </li> 9. <li><a href="#">Item 2</a>< 10. <ul> 11. <li><a href="#">Subitem 1</a></li> 12. <li><a href="#">Subitem 2</a></li> 13. </ul> 14. </li> 15. </ul>

General Structure
For our Mega Menu, instead of nested lists, well simply use standard DIVs, which will work like any nested list : view plaincopy to clipboardprint? 1. <ul id="menu"> 2. <li><a href="#">Item 1</a> 3. <div> 4. Drop down Content 5. <div> 6. </li> 7. <li><a href="#">Item 2</a> 8. <div> 9. Drop down Content 10. <div> 11. </li> 12. </ul> This will be the basic structure for the drop down. The idea behind it is to be able to include any kind of content, such as paragraphs, images, custom lists or a contact form, organized into columns.

3 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

Drop Down Containers


Containers with different sizes will hold the entire drop down content. Ive chosen the tag names according to the number of columns they will contain. To hide the drop downs, well use absolute positioning with a negative left margin : view plaincopy to clipboardprint? 1. position:absolute; 2. left:-999em; The background fallback color is the same as the one used for the menu items. Modern browsers will display a gradient starting with #EEEEEE at the top (to match the parent menu item gradient) and ending with #BBBBBB at the bottom: view plaincopy to clipboardprint? 1. background:#F4F4F4; 2. background: -moz-linear-gradient(top, #EEEEEE, #BBBBBB); 3. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB)); Well again use rounded corners, except for the top left one : view plaincopy to clipboardprint? 1. -moz-border-radius: 0px 5px 5px 5px; 2. -webkit-border-radius: 0px 5px 5px 5px; 3. border-radius: 0px 5px 5px 5px; view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. .dropdown_1column, .dropdown_2columns, .dropdown_3columns, .dropdown_4columns, .dropdown_5columns { margin:4px auto; position:absolute; left:-999em; /* Hides the drop down */ text-align:left; padding:10px 5px 10px 5px; border:1px solid #777777; border-top:none; /* Gradient background */ background:#F4F4F4; background: -moz-linear-gradient(top, #EEEEEE, #BBBBBB); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB)); /* Rounded Corners */ -moz-border-radius: 0px 5px 5px 5px; -webkit-border-radius: 0px 5px 5px 5px; border-radius: 0px 5px 5px 5px; }

To illustrate this, lets see how it would look if we hadnt paid attention to detail:

Now here is our example:

As you can see, the drop down sticks nicely to its parent menu item. In order to have a perfect drop down container, we need to specify the width for each one : view plaincopy to clipboardprint? 1. 2. 3. 4. 5. .dropdown_1column {width: 140px;} .dropdown_2columns {width: 280px;} .dropdown_3columns {width: 420px;} .dropdown_4columns {width: 560px;} .dropdown_5columns {width: 700px;}

And to show the drop downs on mouse hover, well simply use : view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. #menu li:hover .dropdown_1column, #menu li:hover .dropdown_2columns, #menu li:hover .dropdown_3columns, #menu li:hover .dropdown_4columns, #menu li:hover .dropdown_5columns { left:-1px;top:auto; }

Using the Drop Down Containers


Our classes are ready to be included in our menu. Well use each one of them starting from the 5-column, layout to the single column drop down : view plaincopy to clipboardprint? 1. <ul id="menu"> 2. <li><a href="#">Home</a></li> 3. <li><a href="#" class="drop">5 Columns</a> 4. <div class="dropdown_5columns"> 5. <p>5 Columns content</p> 6. </div> 7. </li>

4 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

8. <li><a href="#" class="drop">4 Columns</a> 9. <div class="dropdown_4columns"> 10. <p>4 Columns content</p> 11. </div> 12. </li> 13. <li><a href="#" class="drop">3 Columns</a> 14. <div class="dropdown_3columns"> 15. <p>3 Columns content</p> 16. </div> 17. </li> 18. <li><a href="#" class="drop">2 Columns</a> 19. <div class="dropdown_2columns"> 20. <p>2 Columns content</p> 21. </div> 22. </li> 23. <li><a href="#" class="drop">1 Column</a> 24. <div class="dropdown_1column"> 25. <p>1 Column content</p> 26. </div> 27. </li> 28. </ul> Here is a preview of the code above :

Step 3: Creating the Drop Down Container Columns


Now that we have the containers ready, well create columns of increasing sizes, following the principles of the 960 grid system. view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. .col_1, .col_2, .col_3, .col_4, .col_5 { display:inline; float: left; position: relative; margin-left: 5px; margin-right: 5px; } .col_1 {width:130px;} .col_2 {width:270px;} .col_3 {width:410px;} .col_4 {width:550px;} .col_5 {width:690px;}

Using Columns
Here is an example of a drop down containing several columns. In this example, we have different combinations using all kinds of columns : view plaincopy to clipboardprint? 1. <ul id="menu"> 2. <li><a href="#" class="drop">5 Columns</a> 3. <div class="dropdown_5columns"> 4. <div class="col_5"> 5. <p>This is a 5 Columns content</p> 6. </div> 7. <div class="col_1"> 8. <p>This is a 1 Column content</p> 9. </div> 10. <div class="col_1"> 11. <p>This is a 1 Column content</p> 12. </div> 13. <div class="col_1"> 14. <p>This is a 1 Column content</p> 15. </div> 16. <div class="col_1"> 17. <p>This is a 1 Column content</p> 18. </div> 19. <div class="col_1"> 20. <p>This is a 1 Column content</p> 21. </div> 22. <div class="col_4"> 23. <p>This is a 4 Columns content</p> 24. </div> 25. <div class="col_1"> 26. <p>This is a 1 Column content</p> 27. </div> 28. <div class="col_3"> 29. <p>This is a 3 Columns content</p> 30. </div> 31. <div class="col_2"> 32. <p>This is a 2 Columns content</p> 33. </div> 34. </div> 35. </li> 36. </ul> Code preview :

5 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

Step 4: Aligning to the Right


Now, lets see how we can align our menu and the drop down content to the right edge of the navigation bar; not only the menu item, but the drop down container should also be changed. To accomplish this, well add a new class called .menu_right to the parent list item, so we reset the right margin and float it to the right : view plaincopy to clipboardprint? 1. #menu .menu_right { 2. float:rightright; 3. margin-right:0px; 4. } Next, lets see the drop down. In the previous CSS code, rounded corners were applied to all corners except the left-top one to, in order to match the background of the parent menu item. Now we want this drop down to stick to the right edge of the parent menu item. So, well overwrite the border-radius values with a new class called .align_right, and set the top-right corner to 0. view plaincopy to clipboardprint? 1. #menu li .align_right { 2. /* Rounded Corners */ 3. -moz-border-radius: 5px 0px 5px 5px; 4. -webkit-border-radius: 5px 0px 5px 5px; 5. border-radius: 5px 0px 5px 5px; 6. } Last but not least, we want to make the drop down appear on the right; so well use our new class and reset the left value, then make it stick to the right : view plaincopy to clipboardprint? 1. #menu li:hover .align_right { 2. left:auto; 3. rightright:-1px; 4. top:auto; 5. } Now its ready to be used in the menu : view plaincopy to clipboardprint? 1. <li class="menu_right"><a href="#" class="drop">Right</a> 2. <div class="dropdown_1column align_right"> 3. <div class="col_1"> 4. <p>This is a 1 Column content</p> 5. </div> 6. </div> 7. </li> And a small preview of the code above :

Step 5: Adding and Styling Content


Now that we have the whole structure ready, we can add as much content as we want: text, lists, images, etc.

General Stylings
Lets begin with some basic styling for paragraphs and headings : view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. #menu p, #menu h2, #menu h3, #menu ul li { font-family:Arial, Helvetica, sans-serif; line-height:21px; font-size:12px; text-align:left; text-shadow: 1px 1px 1px #FFFFFF; } #menu h2 { font-size:21px; font-weight:400; letter-spacing:-1px; margin:7px 0 14px 0; padding-bottom:14px; border-bottom:1px solid #666666; } #menu h3 { font-size:14px; margin:7px 0 14px 0; padding-bottom:7px; border-bottom:1px solid #888888; } #menu p { line-height:18px; margin:0 0 10px 0; } .strong { font-weight:bold; } .italic {

6 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

30. font-style:italic; 31. } We can apply a nice blue color to the links within the drop down : view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. #menu li:hover div a { font-size:12px; color:#015b86; } #menu li:hover div a:hover { color:#029feb; }

Lists Stylings
Lets revamp our lists; we have to reset some styling such as the background color or the borders which are used in the navigation bar : view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. #menu li ul { list-style:none; padding:0; margin:0 0 12px 0; } #menu li ul li { font-size:12px; line-height:24px; position:relative; text-shadow: 1px 1px 1px #ffffff; padding:0; margin:0; float:none; text-align:left; width:130px; } #menu li ul li:hover { background:none; border:none; padding:0; margin:0; }

Styling Images
view plaincopy to clipboardprint? 1. .imgshadow { 2. background:#FFFFFF; 3. padding:4px; 4. border:1px solid #777777; 5. margin-top:5px; 6. -moz-box-shadow:0px 0px 5px #666666; 7. -webkit-box-shadow:0px 0px 5px #666666; 8. box-shadow:0px 0px 5px #666666; 9. } And to create a paragraph with an image on the left : view plaincopy to clipboardprint? 1. .img_left { 2. width:auto; 3. float:left; 4. margin:5px 15px 5px 5px; 5. }

Text Boxes
To highlight some content, here is an example of a dark box with rounded corners and a subtle inset shadow : view plaincopy to clipboardprint? 1. #menu li .black_box { 2. background-color:#333333; 3. color: #eeeeee; 4. text-shadow: 1px 1px 1px #000; 5. padding:4px 6px 4px 6px; 6. /* Rounded Corners */ 7. -moz-border-radius: 5px; 8. -webkit-border-radius: 5px; 9. border-radius: 5px; 10. /* Shadow */ 11. -webkit-box-shadow:inset 0 0 3px #000000; 12. -moz-box-shadow:inset 0 0 3px #000000; 13. box-shadow:inset 0 0 3px #000000; 14. }

Restylings Lists
And to finish, heres another way to style your lists using, again, some CSS3 : view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. #menu li .greybox li { background:#F4F4F4; border:1px solid #bbbbbb; margin:0px 0px 4px 0px; padding:4px 6px 4px 6px; width:116px; /* Rounded Corners */ -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } #menu li .greybox li:hover { background:#ffffff; border:1px solid #aaaaaa; padding:4px 6px 4px 6px; margin:0px 0px 4px 0px; }

Step 6: Handling Browser Compatibility and IE6


All browsers handle hover on non-anchor tags . . . except Internet Explorer 6; so our Mega Menu is still not working with this old browser. We can fix this problem thanks to a behavior file that will add this functionality. You can find it here, and use conditional

7 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

comments to target IE6 only; more explanations can be found via this article from CSS-Tricks. To target IE6, well use the following code : view plaincopy to clipboardprint? 1. 2. 3. 4. 5. <!--[if IE 6]> <style> body {behavior: url("csshover3.htc");} </style> <![endif]-->

Ive used a few PNG files in this tutorial, and, as everyone knows, IE6 doesnt support transparency so we have different solutions : Convert them to GIF or PNG-8 format Use a script Set a background color other than the default grey with TweakPNG for example Ill let you choose the one that fits to your needs. Now, lets review a full working example.

Final Example HTML Part


view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="menu.css" type="text/css" media="screen" /> <title>Mega Drop Down Menu</title> <!--[if IE 6]> <style> body {behavior: url("csshover3.htc");} #menu li .drop {background:url("img/drop.gif") no-repeat right 8px; </style> <![endif]--> </head> <body> <ul id="menu"> <li><a href="#" class="drop">Home</a> <div class="dropdown_2columns"> <div class="col_2"> <h2>Welcome !</h2> </div> <div class="col_2"> <p>Hi and welcome here ! This is a showcase of the possibilities of this awesome Mega Drop Down Menu.</p> <p>This item comes with a large range of prepared typographic stylings such as headings, lists, etc.</p> </div> <div class="col_2"> <h2>Cross Browser Support</h2> </div> <div class="col_1"> <img src="img/browsers.png" width="125" height="48" alt="" /> </div> <div class="col_1"> <p>This mega menu has been tested in all major browsers.</p> </div> </div> </li> <li><a href="#" class="drop">5 Columns</a> <div class="dropdown_5columns"> <div class="col_5"> <h2>This is an example of a large container with 5 columns</h2> </div> <div class="col_1"> <p class="black_box">This is a dark grey box text. Fusce in metus at enim porta lacinia vitae a arcu. Sed sed lacus nulla mollis porta quis.</p> </div> <div class="col_1"> <p>Phasellus vitae sapien ac leo mollis porta quis sit amet nisi. Mauris hendrerit, metus cursus accumsan tincidunt.</p> </div> <div class="col_1"> <p class="italic">This is a sample of an italic text. Consequat scelerisque. Fusce sed lectus at arcu mollis accumsan at nec nisi porta quis sit amet.</p> </div> <div class="col_1"> <p>Curabitur euismod gravida ante nec commodo. Nunc dolor nulla, semper in ultricies vitae, vulputate porttitor neque.</p> </div> <div class="col_1"> <p class="strong">This is a sample of a bold text. Aliquam sodales nisi nec felis hendrerit ac eleifend lectus feugiat scelerisque.</p> </div> <div class="col_5"> <h2>Here is some content with side images</h2> </div> <div class="col_3"> <img src="img/01.jpg" width="70" height="70" class="img_left imgshadow" alt="" /> <p>Maecenas eget eros lorem, nec pellentesque lacus. Aenean dui orci, rhoncus sit amet tristique eu, tristique sed odio. Praesent ut interdum elit. Sed in sem mauris. Aenean a commodo mi. Praesent augue lacus.<a href="#">Read more...</a></p> <img src="img/02.jpg" width="70" height="70" class="img_left imgshadow" alt="" /> <p>Aliquam elementum felis quis felis consequat scelerisque. Fusce sed lectus at arcu mollis accumsan at nec nisi. Aliquam pretium mollis fringilla. Nunc in leo urna, eget varius metus. Aliquam sodales nisi.<a href="#">Read more...</a></p> </div> <div class="col_2"> <p class="black_box">This is a black box, you can use it to highligh some content. Sed sed lacus nulla, et lacinia risus. Phasellus vitae sapien ac leo mollis porta quis sit amet nisi. Mauris hendrerit, metus cursus accumsan tincidunt.Quisque vestibulum nisi non nunc blan </div> </div> </li> <li><a href="#" class="drop">4 Columns</a> <div class="dropdown_4columns"> <div class="col_4"> <h2>This is a heading title</h2> </div> <div class="col_1"> <h3>Some Links</h3> <ul> <li><a href="#">ThemeForest</a></li> <li><a href="#">GraphicRiver</a></li> <li><a href="#">ActiveDen</a></li> <li><a href="#">VideoHive</a></li> <li><a href="#">3DOcean</a></li> </ul> </div> <div class="col_1"> <h3>Useful Links</h3> <ul> <li><a href="#">NetTuts</a></li> <li><a href="#">VectorTuts</a></li> <li><a href="#">PsdTuts</a></li> <li><a href="#">PhotoTuts</a></li> <li><a href="#">ActiveTuts</a></li> </ul> </div> <div class="col_1">

8 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185.

<h3>Other Stuff</h3> <ul> <li><a href="#">FreelanceSwitch</a></li> <li><a href="#">Creattica</a></li> <li><a href="#">WorkAwesome</a></li> <li><a href="#">Mac Apps</a></li> <li><a href="#">Web Apps</a></li> </ul> </div> <div class="col_1"> <h3>Misc</h3> <ul> <li><a href="#">Design</a></li> <li><a href="#">Logo</a></li> <li><a href="#">Flash</a></li> <li><a href="#">Illustration</a></li> <li><a href="#">More...</a></li> </ul> </div> </div> </li> <li class="menu_right"><a href="#" class="drop">1 Column</a> <div class="dropdown_1column align_right"> <div class="col_1"> <ul class="simple"> <li><a href="#">FreelanceSwitch</a></li> <li><a href="#">Creattica</a></li> <li><a href="#">WorkAwesome</a></li> <li><a href="#">Mac Apps</a></li> <li><a href="#">Web Apps</a></li> <li><a href="#">NetTuts</a></li> <li><a href="#">VectorTuts</a></li> <li><a href="#">PsdTuts</a></li> <li><a href="#">PhotoTuts</a></li> <li><a href="#">ActiveTuts</a></li> <li><a href="#">Design</a></li> <li><a href="#">Logo</a></li> <li><a href="#">Flash</a></li> <li><a href="#">Illustration</a></li> <li><a href="#">More...</a></li> </ul> </div> </div> </li> <li class="menu_right"><a href="#" class="drop">3 columns</a> <div class="dropdown_3columns align_right"> <div class="col_3"> <h2>Lists in Boxes</h2> </div> <div class="col_1"> <ul class="greybox"> <li><a href="#">FreelanceSwitch</a></li> <li><a href="#">Creattica</a></li> <li><a href="#">WorkAwesome</a></li> <li><a href="#">Mac Apps</a></li> <li><a href="#">Web Apps</a></li> </ul> </div> <div class="col_1"> <ul class="greybox"> <li><a href="#">ThemeForest</a></li> <li><a href="#">GraphicRiver</a></li> <li><a href="#">ActiveDen</a></li> <li><a href="#">VideoHive</a></li> <li><a href="#">3DOcean</a></li> </ul> </div> <div class="col_1"> <ul class="greybox"> <li><a href="#">Design</a></li> <li><a href="#">Logo</a></li> <li><a href="#">Flash</a></li> <li><a href="#">Illustration</a></li> <li><a href="#">More...</a></li> </ul> </div> <div class="col_3"> <h2>Here are some image examples</h2> </div> <div class="col_3"> <img src="img/02.jpg" width="70" height="70" class="img_left imgshadow" alt="" /> <p>Maecenas eget eros lorem, nec pellentesque lacus. Aenean dui orci, rhoncus sit amet tristique eu, tristique sed odio. Praesent ut interdum elit. Maecenas imperdiet, nibh vitae rutrum vulputate, lorem sem condimentum.<a href="#">Read more... </a></p> <img src="img/01.jpg" width="70" height="70" class="img_left imgshadow" alt="" /> <p>Aliquam elementum felis quis felis consequat scelerisque. Fusce sed lectus at arcu mollis accumsan at nec nisi. Aliquam pretium mollis fringilla. Vestibulum tempor facilisis malesuada. <a href="#">Read more...</a></p> </div> </div> </li> </ul> </body> </html>

CSS Part
view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. body, ul, li { font-size:14px; font-family:Arial, Helvetica, sans-serif; line-height:21px; text-align:left; } /* Navigation Bar */ #menu { list-style:none; width:940px; margin:30px auto 0px auto; height:43px; padding:0px 20px 0px 20px; /* Rounded Corners */ -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; /* Background color and gradients */ background: #014464; background: -moz-linear-gradient(top, #0272a7, #013953); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0272a7), to(#013953)); /* Borders */ border: 1px solid #002232; -moz-box-shadow:inset 0px 0px 1px #edf9ff; -webkit-box-shadow:inset 0px 0px 1px #edf9ff;

9 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147.

box-shadow:inset 0px 0px 1px #edf9ff; } #menu li { float:left; text-align:center; position:relative; padding: 4px 10px 4px 10px; margin-right:30px; margin-top:7px; border:none; } #menu li:hover { border: 1px solid #777777; padding: 4px 9px 4px 9px; /* Background color and gradients */ background: #F4F4F4; background: -moz-linear-gradient(top, #F4F4F4, #EEEEEE); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#EEEEEE)); /* Rounded corners */ -moz-border-radius: 5px 5px 0px 0px; -webkit-border-radius: 5px 5px 0px 0px; border-radius: 5px 5px 0px 0px; } #menu li a { font-family:Arial, Helvetica, sans-serif; font-size:14px; color: #EEEEEE; display:block; outline:0; text-decoration:none; text-shadow: 1px 1px 1px #000; } #menu li:hover a { color:#161616; text-shadow: 1px 1px 1px #FFFFFF; } #menu li .drop { padding-right:21px; background:url("img/drop.png") no-repeat rightright 8px; } #menu li:hover .drop { background:url("img/drop.png") no-repeat rightright 7px; } /* Drop Down */ .dropdown_1column, .dropdown_2columns, .dropdown_3columns, .dropdown_4columns, .dropdown_5columns { margin:4px auto; float:left; position:absolute; left:-999em; /* Hides the drop down */ text-align:left; padding:10px 5px 10px 5px; border:1px solid #777777; border-top:none; /* Gradient background */ background:#F4F4F4; background: -moz-linear-gradient(top, #EEEEEE, #BBBBBB); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB)); /* Rounded Corners */ -moz-border-radius: 0px 5px 5px 5px; -webkit-border-radius: 0px 5px 5px 5px; border-radius: 0px 5px 5px 5px; } .dropdown_1column {width: 140px;} .dropdown_2columns {width: 280px;} .dropdown_3columns {width: 420px;} .dropdown_4columns {width: 560px;} .dropdown_5columns {width: 700px;} #menu li:hover .dropdown_1column, #menu li:hover .dropdown_2columns, #menu li:hover .dropdown_3columns, #menu li:hover .dropdown_4columns, #menu li:hover .dropdown_5columns { left:-1px; top:auto; } /* Columns */ .col_1, .col_2, .col_3, .col_4, .col_5 { display:inline; float: left; position: relative; margin-left: 5px; margin-right: 5px; } .col_1 {width:130px;} .col_2 {width:270px;} .col_3 {width:410px;} .col_4 {width:550px;} .col_5 {width:690px;} /* Right alignment */ #menu .menu_right { float:rightright; margin-right:0px; } #menu li .align_right { /* Rounded Corners */ -moz-border-radius: 5px 0px 5px 5px; -webkit-border-radius: 5px 0px 5px 5px; border-radius: 5px 0px 5px 5px; } #menu li:hover .align_right { left:auto; rightright:-1px; top:auto; } /* Drop Down Content Stylings */ #menu p, #menu h2, #menu h3, #menu ul li { font-family:Arial, Helvetica, sans-serif; line-height:21px; font-size:12px; text-align:left; text-shadow: 1px 1px 1px #FFFFFF; } #menu h2 { font-size:21px;

10 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. 240. 241. 242. 243.

font-weight:400; letter-spacing:-1px; margin:7px 0 14px 0; padding-bottom:14px; border-bottom:1px solid #666666; } #menu h3 { font-size:14px; margin:7px 0 14px 0; padding-bottom:7px; border-bottom:1px solid #888888; } #menu p { line-height:18px; margin:0 0 10px 0; } #menu li:hover div a { font-size:12px; color:#015b86; } #menu li:hover div a:hover { color:#029feb; } .strong { font-weight:bold; } .italic { font-style:italic; } .imgshadow { background:#FFFFFF; padding:4px; border:1px solid #777777; margin-top:5px; -moz-box-shadow:0px 0px 5px #666666; -webkit-box-shadow:0px 0px 5px #666666; box-shadow:0px 0px 5px #666666; } .img_left { /* Image sticks to the left */ width:auto; float:left; margin:5px 15px 5px 5px; } #menu li .black_box { background-color:#333333; color: #eeeeee; text-shadow: 1px 1px 1px #000; padding:4px 6px 4px 6px; /* Rounded Corners */ -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; /* Shadow */ -webkit-box-shadow:inset 0 0 3px #000000; -moz-box-shadow:inset 0 0 3px #000000; box-shadow:inset 0 0 3px #000000; } #menu li ul { list-style:none; padding:0; margin:0 0 12px 0; } #menu li ul li { font-size:12px; line-height:24px; position:relative; text-shadow: 1px 1px 1px #ffffff; padding:0; margin:0; float:none; text-align:left; width:130px; } #menu li ul li:hover { background:none; border:none; padding:0; margin:0; } #menu li .greybox li { background:#F4F4F4; border:1px solid #bbbbbb; margin:0px 0px 4px 0px; padding:4px 6px 4px 6px; width:116px; /* Rounded Corners */ -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } #menu li .greybox li:hover { background:#ffffff; border:1px solid #aaaaaa; padding:4px 6px 4px 6px; margin:0px 0px 4px 0px; }

Interesting and Relevant Links


Designing Drop-Down Menus: Examples and Best Practices Mega Drop-Down Menu, Enjoy It Responsibly! Mega Menus: the Next Web Design Trend Mega Drop-Down Navigation Menus Work Well 25 Examples of Mega Menus in Web Design Mega Drop-Down Menus (46 examples)

Conclusion
I hope youve enjoyed this tutorial on creating mega menus. Thanks for following along!
Like 631 people like this.

11 of 12

12/13/2012 16:54

How to Build a Kick-Butt CSS3 Mega Drop-Down Menu | Nettuts+

http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-a-kick-b...

Guillaume Marty is Pixelworkshop on Codecanyon

Tags: CSScss3

By Guillaume Marty
This author has yet to write their bio.

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more

12 of 12

12/13/2012 16:54

You might also like