Build a Kick-Butt CSS3 Mega Drop-Down Menu

Hi Every body 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, we’ll learn how to build a cross-browser, awesome CSS-only drop-down mega menu, using nice CSS3 features.

Download   Demo


Step 1: Building the Navigation Bar

Let’s begin with a basic menu, built with an unordered list and some basic CSS styling.
  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

We’ll 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”.
  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, let’s 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 :
  1. -moz-border-radius: 10px  
  2. -webkit-border-radius: 10px;  
  3. border-radius: 10px;  
For the background, we’ll 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.
  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 :
  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;  
Here’s the final CSS code for the #menu container :
  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 */  
  8.     -moz-border-radius: 10px;  
  9.     -webkit-border-radius: 10px;  
  10.     border-radius: 10px;  
  11.     /* Background color and gradients */  
  12.     background#014464;  
  13.     background: -moz-linear-gradient(top#0272a7#013953);  
  14.     background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0272a7), to(#013953));  
  15.     /* Borders */  
  16.     border1px solid #002232;  
  17.     -moz-box-shadow:inset 0px 0px 1px #edf9ff;  
  18.     -webkit-box-shadow:inset 0px 0px 1px #edf9ff;  
  19.     box-shadow:inset 0px 0px 1px #edf9ff;  
  20. }  

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) :
  1. #menu li {  
  2.     float:left;  
  3.     display:block;  
  4.     text-align:center;  
  5.     position:relative;  
  6.     padding4px 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 we’ll have the drop down sticking right under the menu items.
  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, we’ll remove 1 pixel of padding on both sides, so we have 9 pixels instead of 10.
  1. border1px solid #777777;  
  2. padding4px 9px 4px 9px;  
Then, we add rounded corners to the top only so the drop down will stick perfectly under the parent menu item :

  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 :
  1. #menu li:hover {  
  2.     border1px solid #777777;  
  3.     padding4px 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, we’ll 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 :
  1. text-shadow1px 1px 1px #000;  
Here is the final CSS for the links :
  1. #menu li a {  
  2.     font-family:ArialHelveticasans-serif;  
  3.     font-size:14px;  
  4.     color#EEEEEE;  
  5.     display:block;  
  6.     outline:0;  
  7.     text-decoration:none;  
  8.     text-shadow1px 1px 1px #000;  
  9. }  
On mouse hover, as the background is grey, we’ll use a darker color (#161616) for the links and the white color for the text shadow :
  1. #menu li:hover a {  
  2.     color:#161616;  
  3.     text-shadow1px 1px 1px #FFFFFF;  
  4. }  
Finally, we need a way to indicate if there’s 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) :
  1. #menu li .drop {  
  2.     padding-right:21px;  
  3.     background:url("img/drop.png"no-repeat rightright 8px;  
  4. }  
  5. #menu li:hover .drop {  
  6.     background:url("img/drop.png"no-repeat rightright 7px;  
  7. }  
Here is our final code for the menu container and links; only the “home” item doesn’t have any drop down content for now :

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

Step 2: Coding the Drop Down

A “classic” drop down menu usually contains lists nested within parent list items and looks like:
  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, we’ll simply use standard DIVs, which will work like any nested list :
  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.

Drop Down Containers

Containers with different sizes will hold the entire drop down content. I’ve chosen the tag names according to the number of columns they will contain.
To hide the drop downs, we’ll use absolute positioning with a negative left margin :
  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:
  1. background:#F4F4F4;  
  2. background: -moz-linear-gradient(top#EEEEEE#BBBBBB);  
  3. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB));  
We’ll again use rounded corners, except for the top left one :
  1. -moz-border-radius: 0px 5px 5px 5px;  
  2. -webkit-border-radius: 0px 5px 5px 5px;  
  3. border-radius: 0px 5px 5px 5px;  
  1. .dropdown_1column,  
  2. .dropdown_2columns,  
  3. .dropdown_3columns,  
  4. .dropdown_4columns,  
  5. .dropdown_5columns {  
  6.     margin:4px auto;  
  7.     position:absolute;  
  8.     left:-999em; /* Hides the drop down */  
  9.     text-align:left;  
  10.     padding:10px 5px 10px 5px;  
  11.     border:1px solid #777777;  
  12.     border-top:none;  
  13.     /* Gradient background */  
  14.     background:#F4F4F4;  
  15.     background: -moz-linear-gradient(top#EEEEEE#BBBBBB);  
  16.     background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB));  
  17.     /* Rounded Corners */  
  18.     -moz-border-radius: 0px 5px 5px 5px;  
  19.     -webkit-border-radius: 0px 5px 5px 5px;  
  20.     border-radius: 0px 5px 5px 5px;  
  21. }  
To illustrate this, let’s see how it would look if we hadn’t paid attention to detail:
Building a CSS3 Mega Drop Down Menu
Now here is our example:
Building a CSS3 Mega Drop Down Menu
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 :
  1. .dropdown_1column {width140px;}  
  2. .dropdown_2columns {width280px;}  
  3. .dropdown_3columns {width420px;}  
  4. .dropdown_4columns {width560px;}  
  5. .dropdown_5columns {width700px;}  
And to show the drop downs on mouse hover, we’ll simply use :
  1. #menu li:hover .dropdown_1column,  
  2. #menu li:hover .dropdown_2columns,  
  3. #menu li:hover .dropdown_3columns,  
  4. #menu li:hover .dropdown_4columns,  
  5. #menu li:hover .dropdown_5columns {  
  6.     left:-1px;top:auto;  
  7. }  

Using the Drop Down Containers

Our classes are ready to be included in our menu. We’ll use each one of them starting from the 5-column, layout to the single column drop down
  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>  
  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 :
Building a CSS3 Mega Drop Down Menu

Step 3: Creating the Drop Down Container Columns

Now that we have the containers ready, we’ll create columns of increasing sizes, following the principles of the 960 grid system.
  1. .col_1,  
  2. .col_2,  
  3. .col_3,  
  4. .col_4,  
  5. .col_5 {  
  6.     display:inline;  
  7.     floatleft;  
  8.     positionrelative;  
  9.     margin-left5px;  
  10.     margin-right5px;  
  11. }  
  12. .col_1 {width:130px;}  
  13. .col_2 {width:270px;}  
  14. .col_3 {width:410px;}  
  15. .col_4 {width:550px;}  
  16. .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 :
  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 :
Building a CSS3 Mega Drop Down Menu

Step 4: Aligning to the Right

Now, let’s 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, we’ll add a new class called .menu_right to the parent list item, so we reset the right margin and float it to the right :
  1. #menu .menu_right {  
  2.     float:rightright;  
  3.     margin-right:0px;  
  4. }  
Next, let’s 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, we’ll overwrite the border-radius values with a new class called .align_right, and set the top-right corner to 0.
  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 we’ll use our new class and reset the left value, then make it stick to the right :
  1. #menu li:hover .align_right {  
  2.     left:auto;  
  3.     rightright:-1px;  
  4.     top:auto;  
  5. }  
Now it’s ready to be used in the menu :
  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 :
Building a CSS3 Mega Drop Down Menu

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

Let’s begin with some basic styling for paragraphs and headings :
  1. #menu p, #menu h2, #menu h3, #menu ul li {  
  2.     font-family:ArialHelveticasans-serif;  
  3.     line-height:21px;  
  4.     font-size:12px;  
  5.     text-align:left;  
  6.     text-shadow1px 1px 1px #FFFFFF;  
  7. }  
  8. #menu h2 {  
  9.     font-size:21px;  
  10.     font-weight:400;  
  11.     letter-spacing:-1px;  
  12.     margin:7px 0 14px 0;  
  13.     padding-bottom:14px;  
  14.     border-bottom:1px solid #666666;  
  15. }  
  16. #menu h3 {  
  17.     font-size:14px;  
  18.     margin:7px 0 14px 0;  
  19.     padding-bottom:7px;  
  20.     border-bottom:1px solid #888888;  
  21. }  
  22. #menu p {  
  23.     line-height:18px;  
  24.     margin:0 0 10px 0;  
  25. }  
  26. .strong {  
  27.     font-weight:bold;  
  28. }  
  29. .italic {  
  30.     font-style:italic;  
  31. }  
We can apply a nice blue color to the links within the drop down :
  1. #menu li:hover div a {  
  2.     font-size:12px;  
  3.     color:#015b86;  
  4. }  
  5. #menu li:hover div a:hover {  
  6.     color:#029feb;  
  7. }  

Lists Stylings

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

Styling Images

  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 :
  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 :
  1. #menu li .black_box {  
  2.     background-color:#333333;  
  3.     color#eeeeee;  
  4.     text-shadow1px 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, here’s another way to style your lists using, again, some CSS3 :
  1. #menu li .greybox li {  
  2.     background:#F4F4F4;  
  3.     border:1px solid #bbbbbb;  
  4.     margin:0px 0px 4px 0px;  
  5.     padding:4px 6px 4px 6px;  
  6.     width:116px;  
  7.     /* Rounded Corners */  
  8.     -moz-border-radius: 5px;  
  9.     -webkit-border-radius: 5px;  
  10.     border-radius: 5px;  
  11. }  
  12. #menu li .greybox li:hover {  
  13.     background:#ffffff;  
  14.     border:1px solid #aaaaaa;  
  15.     padding:4px 6px 4px 6px;  
  16.     margin:0px 0px 4px 0px;  
  17. }  

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 comments to target IE6 only; more explanations can be found via this article from CSS-Tricks.
To target IE6, we’ll use the following code :
  1. <!--[if IE 6]>  
  2. <style>  
  3. body {behavior: url("csshover3.htc");}  
  4. </style>  
  5. <![endif]-->  
I’ve used a few PNG files in this tutorial, and, as everyone knows, IE6 doesn’t 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
I’ll let you choose the one that fits to your needs. Now, let’s review a full working example.

Final Example

HTML Part

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <link rel="stylesheet" href="menu.css" type="text/css" media="screen" />  
  6. <title>Mega Drop Down Menu</title>  
  7. <!--[if IE 6]>  
  8. <style>  
  9. body {behavior: url("csshover3.htc");}  
  10. #menu li .drop {background:url("img/drop.gif") no-repeat right 8px;  
  11. </style>  
  12. <![endif]-->  
  13. </head>  
  14. <body>  
  15. <ul id="menu">  
  16.     <li><a href="#" class="drop">Home</a><!-- Begin Home Item -->  
  17.         <div class="dropdown_2columns"><!-- Begin 2 columns container -->  
  18.             <div class="col_2">  
  19.                 <h2>Welcome !</h2>  
  20.             </div>  
  21.             <div class="col_2">  
  22.                 <p>Hi and welcome here ! This is a showcase of the possibilities of this awesome Mega Drop Down Menu.</p>  
  23.                 <p>This item comes with a large range of prepared typographic stylings such as headings, lists, etc.</p>  
  24.             </div>  
  25.             <div class="col_2">  
  26.                 <h2>Cross Browser Support</h2>  
  27.             </div>  
  28.             <div class="col_1">  
  29.                 <img src="img/browsers.png" width="125" height="48" alt="" />  
  30.             </div>  
  31.             <div class="col_1">  
  32.                 <p>This mega menu has been tested in all major browsers.</p>  
  33.             </div>  
  34.         </div><!-- End 2 columns container -->  
  35.     </li><!-- End Home Item -->  
  36.     <li><a href="#" class="drop">5 Columns</a><!-- Begin 5 columns Item -->  
  37.         <div class="dropdown_5columns"><!-- Begin 5 columns container -->  
  38.             <div class="col_5">  
  39.                 <h2>This is an example of a large container with 5 columns</h2>  
  40.             </div>  
  41.             <div class="col_1">  
  42.                 <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>  
  43.             </div>  
  44.             <div class="col_1">  
  45.                 <p>Phasellus vitae sapien ac leo mollis porta quis sit amet nisi. Mauris hendrerit, metus cursus accumsan tincidunt.</p>  
  46.             </div>  
  47.             <div class="col_1">  
  48.                 <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>  
  49.             </div>  
  50.             <div class="col_1">  
  51.                 <p>Curabitur euismod gravida ante nec commodo. Nunc dolor nulla, semper in ultricies vitae, vulputate porttitor neque.</p>  
  52.             </div>  
  53.             <div class="col_1">  
  54.                 <p class="strong">This is a sample of a bold text. Aliquam sodales nisi nec felis hendrerit ac eleifend lectus feugiat scelerisque.</p>  
  55.             </div>  
  56.             <div class="col_5">  
  57.                 <h2>Here is some content with side images</h2>  
  58.             </div>  
  59.             <div class="col_3">  
  60.                 <img src="img/01.jpg" width="70" height="70" class="img_left imgshadow" alt="" />  
  61.                 <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>  
  62.                 <img src="img/02.jpg" width="70" height="70" class="img_left imgshadow" alt="" />  
  63.                 <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>  
  64.             </div>  
  65.             <div class="col_2">  
  66.                 <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 blandit placerat. Mauris facilisis, risus ut lobortis posuere, diam lacus congue lorem, ut condimentum ligula est vel orci. Donec interdum lacus at velit varius gravida. Nulla ipsum risus.</p>  
  67.             </div>  
  68.         </div><!-- End 5 columns container -->  
  69.     </li><!-- End 5 columns Item -->  
  70.     <li><a href="#" class="drop">4 Columns</a><!-- Begin 4 columns Item -->  
  71.         <div class="dropdown_4columns"><!-- Begin 4 columns container -->  
  72.             <div class="col_4">  
  73.                 <h2>This is a heading title</h2>  
  74.             </div>  
  75.             <div class="col_1">  
  76.                 <h3>Some Links</h3>  
  77.                 <ul>  
  78.                     <li><a href="#">ThemeForest</a></li>  
  79.                     <li><a href="#">GraphicRiver</a></li>  
  80.                     <li><a href="#">ActiveDen</a></li>  
  81.                     <li><a href="#">VideoHive</a></li>  
  82.                     <li><a href="#">3DOcean</a></li>  
  83.                 </ul>  
  84.             </div>  
  85.             <div class="col_1">  
  86.                 <h3>Useful Links</h3>  
  87.                 <ul>  
  88.                     <li><a href="#">NetTuts</a></li>  
  89.                     <li><a href="#">VectorTuts</a></li>  
  90.                     <li><a href="#">PsdTuts</a></li>  
  91.                     <li><a href="#">PhotoTuts</a></li>  
  92.                     <li><a href="#">ActiveTuts</a></li>  
  93.                 </ul>  
  94.             </div>  
  95.             <div class="col_1">  
  96.                 <h3>Other Stuff</h3>  
  97.                 <ul>  
  98.                     <li><a href="#">FreelanceSwitch</a></li>  
  99.                     <li><a href="#">Creattica</a></li>  
  100.                     <li><a href="#">WorkAwesome</a></li>  
  101.                     <li><a href="#">Mac Apps</a></li>  
  102.                     <li><a href="#">Web Apps</a></li>  
  103.                 </ul>  
  104.             </div>  
  105.             <div class="col_1">  
  106.                 <h3>Misc</h3>  
  107.                 <ul>  
  108.                     <li><a href="#">Design</a></li>  
  109.                     <li><a href="#">Logo</a></li>  
  110.                     <li><a href="#">Flash</a></li>  
  111.                     <li><a href="#">Illustration</a></li>  
  112.                     <li><a href="#">More...</a></li>  
  113.                 </ul>  
  114.             </div>  
  115.         </div><!-- End 4 columns container -->  
  116.     </li><!-- End 4 columns Item -->  
  117.     <li class="menu_right"><a href="#" class="drop">1 Column</a>  
  118.         <div class="dropdown_1column align_right">  
  119.                 <div class="col_1">  
  120.                     <ul class="simple">  
  121.                         <li><a href="#">FreelanceSwitch</a></li>  
  122.                         <li><a href="#">Creattica</a></li>  
  123.                         <li><a href="#">WorkAwesome</a></li>  
  124.                         <li><a href="#">Mac Apps</a></li>  
  125.                         <li><a href="#">Web Apps</a></li>  
  126.                         <li><a href="#">NetTuts</a></li>  
  127.                         <li><a href="#">VectorTuts</a></li>  
  128.                         <li><a href="#">PsdTuts</a></li>  
  129.                         <li><a href="#">PhotoTuts</a></li>  
  130.                         <li><a href="#">ActiveTuts</a></li>  
  131.                         <li><a href="#">Design</a></li>  
  132.                         <li><a href="#">Logo</a></li>  
  133.                         <li><a href="#">Flash</a></li>  
  134.                         <li><a href="#">Illustration</a></li>  
  135.                         <li><a href="#">More...</a></li>  
  136.                     </ul>  
  137.                 </div>  
  138.         </div>  
  139.     </li>  
  140.     <li class="menu_right"><a href="#" class="drop">3 columns</a><!-- Begin 3 columns Item -->  
  141.         <div class="dropdown_3columns align_right"><!-- Begin 3 columns container -->  
  142.             <div class="col_3">  
  143.                 <h2>Lists in Boxes</h2>  
  144.             </div>  
  145.             <div class="col_1">  
  146.                 <ul class="greybox">  
  147.                     <li><a href="#">FreelanceSwitch</a></li>  
  148.                     <li><a href="#">Creattica</a></li>  
  149.                     <li><a href="#">WorkAwesome</a></li>  
  150.                     <li><a href="#">Mac Apps</a></li>  
  151.                     <li><a href="#">Web Apps</a></li>  
  152.                 </ul>  
  153.             </div>  
  154.             <div class="col_1">  
  155.                 <ul class="greybox">  
  156.                     <li><a href="#">ThemeForest</a></li>  
  157.                     <li><a href="#">GraphicRiver</a></li>  
  158.                     <li><a href="#">ActiveDen</a></li>  
  159.                     <li><a href="#">VideoHive</a></li>  
  160.                     <li><a href="#">3DOcean</a></li>  
  161.                 </ul>  
  162.             </div>  
  163.             <div class="col_1">  
  164.                 <ul class="greybox">  
  165.                     <li><a href="#">Design</a></li>  
  166.                     <li><a href="#">Logo</a></li>  
  167.                     <li><a href="#">Flash</a></li>  
  168.                     <li><a href="#">Illustration</a></li>  
  169.                     <li><a href="#">More...</a></li>  
  170.                 </ul>  
  171.             </div>  
  172.             <div class="col_3">  
  173.                 <h2>Here are some image examples</h2>  
  174.             </div>  
  175.             <div class="col_3">  
  176.                 <img src="img/02.jpg" width="70" height="70" class="img_left imgshadow" alt="" />  
  177.                 <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>  
  178.                 <img src="img/01.jpg" width="70" height="70" class="img_left imgshadow" alt="" />  
  179.                 <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>  
  180.             </div>  
  181.         </div><!-- End 3 columns container -->  
  182.     </li><!-- End 3 columns Item -->  
  183. </ul>  
  184. </body>  
  185. </html>  

CSS Part

  1. body, ul, li {  
  2.     font-size:14px;  
  3.     font-family:ArialHelveticasans-serif;  
  4.     line-height:21px;  
  5.     text-align:left;  
  6. }  
  7. /* Navigation Bar */  
  8. #menu {  
  9.     list-style:none;  
  10.     width:940px;  
  11.     margin:30px auto 0px auto;  
  12.     height:43px;  
  13.     padding:0px 20px 0px 20px;  
  14.     /* Rounded Corners */  
  15.     -moz-border-radius: 10px;  
  16.     -webkit-border-radius: 10px;  
  17.     border-radius: 10px;  
  18.     /* Background color and gradients */  
  19.     background#014464;  
  20.     background: -moz-linear-gradient(top#0272a7#013953);  
  21.     background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0272a7), to(#013953));  
  22.     /* Borders */  
  23.     border1px solid #002232;  
  24.     -moz-box-shadow:inset 0px 0px 1px #edf9ff;  
  25.     -webkit-box-shadow:inset 0px 0px 1px #edf9ff;  
  26.     box-shadow:inset 0px 0px 1px #edf9ff;  
  27. }  
  28. #menu li {  
  29.     float:left;  
  30.     text-align:center;  
  31.     position:relative;  
  32.     padding4px 10px 4px 10px;  
  33.     margin-right:30px;  
  34.     margin-top:7px;  
  35.     border:none;  
  36. }  
  37. #menu li:hover {  
  38.     border1px solid #777777;  
  39.     padding4px 9px 4px 9px;  
  40.     /* Background color and gradients */  
  41.     background#F4F4F4;  
  42.     background: -moz-linear-gradient(top#F4F4F4#EEEEEE);  
  43.     background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#EEEEEE));  
  44.     /* Rounded corners */  
  45.     -moz-border-radius: 5px 5px 0px 0px;  
  46.     -webkit-border-radius: 5px 5px 0px 0px;  
  47.     border-radius: 5px 5px 0px 0px;  
  48. }  
  49. #menu li a {  
  50.     font-family:ArialHelveticasans-serif;  
  51.     font-size:14px;  
  52.     color#EEEEEE;  
  53.     display:block;  
  54.     outline:0;  
  55.     text-decoration:none;  
  56.     text-shadow1px 1px 1px #000;  
  57. }  
  58. #menu li:hover a {  
  59.     color:#161616;  
  60.     text-shadow1px 1px 1px #FFFFFF;  
  61. }  
  62. #menu li .drop {  
  63.     padding-right:21px;  
  64.     background:url("img/drop.png"no-repeat rightright 8px;  
  65. }  
  66. #menu li:hover .drop {  
  67.     background:url("img/drop.png"no-repeat rightright 7px;  
  68. }  
  69. /* Drop Down */  
  70. .dropdown_1column,  
  71. .dropdown_2columns,  
  72. .dropdown_3columns,  
  73. .dropdown_4columns,  
  74. .dropdown_5columns {  
  75.     margin:4px auto;  
  76.     float:left;  
  77.     position:absolute;  
  78.     left:-999em; /* Hides the drop down */  
  79.     text-align:left;  
  80.     padding:10px 5px 10px 5px;  
  81.     border:1px solid #777777;  
  82.     border-top:none;  
  83.     /* Gradient background */  
  84.     background:#F4F4F4;  
  85.     background: -moz-linear-gradient(top#EEEEEE#BBBBBB);  
  86.     background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB));  
  87.     /* Rounded Corners */  
  88.     -moz-border-radius: 0px 5px 5px 5px;  
  89.     -webkit-border-radius: 0px 5px 5px 5px;  
  90.     border-radius: 0px 5px 5px 5px;  
  91. }  
  92. .dropdown_1column {width140px;}  
  93. .dropdown_2columns {width280px;}  
  94. .dropdown_3columns {width420px;}  
  95. .dropdown_4columns {width560px;}  
  96. .dropdown_5columns {width700px;}  
  97. #menu li:hover .dropdown_1column,  
  98. #menu li:hover .dropdown_2columns,  
  99. #menu li:hover .dropdown_3columns,  
  100. #menu li:hover .dropdown_4columns,  
  101. #menu li:hover .dropdown_5columns {  
  102.     left:-1px;  
  103.     top:auto;  
  104. }  
  105. /* Columns */  
  106. .col_1,  
  107. .col_2,  
  108. .col_3,  
  109. .col_4,  
  110. .col_5 {  
  111.     display:inline;  
  112.     floatleft;  
  113.     positionrelative;  
  114.     margin-left5px;  
  115.     margin-right5px;  
  116. }  
  117. .col_1 {width:130px;}  
  118. .col_2 {width:270px;}  
  119. .col_3 {width:410px;}  
  120. .col_4 {width:550px;}  
  121. .col_5 {width:690px;}  
  122. /* Right alignment */  
  123. #menu .menu_right {  
  124.     float:rightright;  
  125.     margin-right:0px;  
  126. }  
  127. #menu li .align_right {  
  128.     /* Rounded Corners */  
  129.     -moz-border-radius: 5px 0px 5px 5px;  
  130.     -webkit-border-radius: 5px 0px 5px 5px;  
  131.     border-radius: 5px 0px 5px 5px;  
  132. }  
  133. #menu li:hover .align_right {  
  134.     left:auto;  
  135.     rightright:-1px;  
  136.     top:auto;  
  137. }  
  138. /* Drop Down Content Stylings */  
  139. #menu p, #menu h2, #menu h3, #menu ul li {  
  140.     font-family:ArialHelveticasans-serif;  
  141.     line-height:21px;  
  142.     font-size:12px;  
  143.     text-align:left;  
  144.     text-shadow1px 1px 1px #FFFFFF;  
  145. }  
  146. #menu h2 {  
  147.     font-size:21px;  
  148.     font-weight:400;  
  149.     letter-spacing:-1px;  
  150.     margin:7px 0 14px 0;  
  151.     padding-bottom:14px;  
  152.     border-bottom:1px solid #666666;  
  153. }  
  154. #menu h3 {  
  155.     font-size:14px;  
  156.     margin:7px 0 14px 0;  
  157.     padding-bottom:7px;  
  158.     border-bottom:1px solid #888888;  
  159. }  
  160. #menu p {  
  161.     line-height:18px;  
  162.     margin:0 0 10px 0;  
  163. }  
  164. #menu li:hover div a {  
  165.     font-size:12px;  
  166.     color:#015b86;  
  167. }  
  168. #menu li:hover div a:hover {  
  169.     color:#029feb;  
  170. }  
  171. .strong {  
  172.     font-weight:bold;  
  173. }  
  174. .italic {  
  175.     font-style:italic;  
  176. }  
  177. .imgshadow {  
  178.     background:#FFFFFF;  
  179.     padding:4px;  
  180.     border:1px solid #777777;  
  181.     margin-top:5px;  
  182.     -moz-box-shadow:0px 0px 5px #666666;  
  183.     -webkit-box-shadow:0px 0px 5px #666666;  
  184.     box-shadow:0px 0px 5px #666666;  
  185. }  
  186. .img_left { /* Image sticks to the left */  
  187.     width:auto;  
  188.     float:left;  
  189.     margin:5px 15px 5px 5px;  
  190. }  
  191. #menu li .black_box {  
  192.     background-color:#333333;  
  193.     color#eeeeee;  
  194.     text-shadow1px 1px 1px #000;  
  195.     padding:4px 6px 4px 6px;  
  196.     /* Rounded Corners */  
  197.     -moz-border-radius: 5px;  
  198.     -webkit-border-radius: 5px;  
  199.     border-radius: 5px;  
  200.     /* Shadow */  
  201.     -webkit-box-shadow:inset 0 0 3px #000000;  
  202.     -moz-box-shadow:inset 0 0 3px #000000;  
  203.     box-shadow:inset 0 0 3px #000000;  
  204. }  
  205. #menu li ul {  
  206.     list-style:none;  
  207.     padding:0;  
  208.     margin:0 0 12px 0;  
  209. }  
  210. #menu li ul li {  
  211.     font-size:12px;  
  212.     line-height:24px;  
  213.     position:relative;  
  214.     text-shadow1px 1px 1px #ffffff;  
  215.     padding:0;  
  216.     margin:0;  
  217.     float:none;  
  218.     text-align:left;  
  219.     width:130px;  
  220. }  
  221. #menu li ul li:hover {  
  222.     background:none;  
  223.     border:none;  
  224.     padding:0;  
  225.     margin:0;  
  226. }  
  227. #menu li .greybox li {  
  228.     background:#F4F4F4;  
  229.     border:1px solid #bbbbbb;  
  230.     margin:0px 0px 4px 0px;  
  231.     padding:4px 6px 4px 6px;  
  232.     width:116px;  
  233.     /* Rounded Corners */  
  234.     -moz-border-radius: 5px;  
  235.     -webkit-border-radius: 5px;  
  236.     border-radius: 5px;  
  237. }  
  238. #menu li .greybox li:hover {  
  239.     background:#ffffff;  
  240.     border:1px solid #aaaaaa;  
  241.     padding:4px 6px 4px 6px;  
  242.     margin:0px 0px 4px 0px;  
  243. }
  244.  

Interesting and Relevant Links


Conclusion

I hope you’ve enjoyed this tutorial on creating mega menus. Thanks for following along!

No comments:

Post a Comment