All posts tagged HTML

How to Make a Mega Drop-Down Menu

Mega drop-down menus are not actually new, but more and more we see them on popular websites and blogs. With the ever increasing quantity of content on the web we have to figure out solutions to display content and navigation but still keep everything usable and provide a good user experience. It’s no wonder mega drop-downs are now used more often.

Today we’ll take a look at creating a simple HTML site with a horizontal navigation bar where a menu item will have a mega drop-down attached to it. I used jQuery for the drop-down and some CSS3 for the rounded corners.

First of all we’ll need a design:

screenshot_thumbnail

Step 1 – The Markup

Before we can start working on the mega drop-down menu we will need a working site so let’s write our HTML. Of course for the purpose of this tutorial the links in the menu won’t work.

Let’s start with the header. We’ll include our style.css file and the jQuery library (you can download the jQuery library here.)

<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>
<html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;>

<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; />
<title>Mega Drop-Down Menu Demo</title>
<link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; />
<script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.2.min.js&quot;></script>
</head>

Then we will add a H1 and a paragraph that explains what the demo site is about:

<body>
<h1>Mega Drop-Down Menu Demo Site</h1>
<p>This page is an example of a mega drop-down menu, but with more options than the usual suckerfish drop downs. We used jQuery, CSS3 and HTML to create this mega drop down menu.</p>

And then our navigation bar (without the drop-down for now):

<div>
<ul>
<li><a href=&quot;#&quot;>home</a></li>
<li><a href=&quot;#&quot;>about</a></li>
<li><a href=&quot;#&quot;>services</a></li>
<li><a href=&quot;#&quot;>products</a></li>
<li><a href=&quot;#&quot;>portfolio</a></li>
<li><a href=&quot;#&quot;>contact</a></li>
</ul>
</div>

We have 6 menu items and we will use the ‘services’ tab and attach our drop-down to it. But before we do that let’s add some content to our site. We’ll put 2 paragraphs with some Lorem Ipsum inside a div.

<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eget eros libero. Fusce tempus quam sit amet erat mollis a fermentum nibh imperdiet. Fusce iaculis sapien in turpis aliquet porta. Donec tincidunt gravida tortor, vel dignissim augue convallis sit amet. Aliquam auctor ornare accumsan. Cras convallis elit tincidunt arcu semper egestas. Mauris interdum fringilla nisi. Cras a dapibus lectus. Praesent blandit ullamcorper ornare. Nam hendrerit sollicitudin urna non ultricies. Phasellus condimentum auctor risus, at accumsan tellus tempor vel. Nunc mattis eleifend dolor at adipiscing.</p>

<p>Ut purus metus, fermentum vitae pulvinar vel, elementum eget nulla. Pellentesque posuere, enim ut dapibus vestibulum, leo nunc porttitor neque, sed pulvinar orci sem eleifend sapien. Nullam at odio nibh, eu pharetra ipsum. Pellentesque eget ante nec ante consequat ullamcorper a vitae mauris. Integer lacus lorem, sollicitudin vulputate posuere at, commodo a sapien. Vivamus lobortis vehicula imperdiet. Donec a congue tortor. Fusce augue tortor, pretium pharetra pellentesque ornare, laoreet nec sapien. Ut eget magna tellus. Pellentesque posuere accumsan condimentum.</p>
</div>

And then we can end our document with the closing body and html tags.

Before we dive into the CSS, let’s add our drop-down. Here’s the new markup for the menu. I added a class to the ‘services’ list item since this is the one that will have the mega drop-down and I added a div with some content in it.

<div>
<ul>
<li><a href=&quot;#&quot;>home</a></li>
<li><a href=&quot;#&quot;>about</a></li>
<li><a href=&quot;#&quot;>services</a></li>

<div class=&quot;servicesdropped&quot;>
<p>Here's an example of a paragraph inside the drop-down panel. We placed this paragraph in the left column. Then we have 2 more columns on the right with a H3 for the section title and then we have unordered lists.</p>
<ul>
<h3>Design Services</h3>
<li><a href=&quot;#&quot;>Web Design</a></li>
<li><a href=&quot;#&quot;>Hosting Solutions</a></li>
<li><a href=&quot;#&quot;>Logo Design</a></li>
<li><a href=&quot;#&quot;>e-Commerce</a></li>
<li><a href=&quot;#&quot;>WordPress Integration</a></li>
<li><a href=&quot;#&quot;>PSD/PNG Conversion</a></li>
</ul>
<ul>
<h3>Writing Services</h3>
<li><a href=&quot;#&quot;>Freelance Writing</a></li>
<li><a href=&quot;#&quot;>Blogging</a></li>
<li><a href=&quot;#&quot;>Proofreading</a></li>
<li><a href=&quot;#&quot;>Copywriting</a></li>
<li><a href=&quot;#&quot;>Ghost Writing</a></li>
<li><a href=&quot;#&quot;>Marketing Plan</a></li>
</ul>
</div>

<li><a href=&quot;#&quot;>products</a></li>
<li><a href=&quot;#&quot;>portfolio</a></li>
<li><a href=&quot;#&quot;>contact</a></li>
</ul>
</div>

As you can see the whole mega drop-down panel is contained within the div=”servicesdropped”. I put a paragraph and some unordered lists in there (later styled using CSS)

Now we have a working HTML website. Of course without CSS it doesn’t look very good as you can see:

unstyled_screenshot

Part 2 – jQuery

Now let’s work on the jQuery part. It’s actually very simple. I want the ‘services’ tab to open up a mega drop-down panel when clicked. And I want the panel to close the ‘services’ tab is clicked again.

Let’s insert this code in the head of our document:

<script type=&quot;text/javascript&quot;>
$(document).ready(function(){
$(&quot;.downservices&quot;).click(function(){
$(&quot;.servicesdropped&quot;).toggle(&quot;fast&quot;);
});
});
</script>

This will tell the browser to toggle the panel with a class of .servicesdropped up and down when the list item with a class of .downservices is clicked. Simple huh?

Step 3 – CSS3

I used some CSS3 to give our divs and paragraphs some rounded corners. Of course the rest of the CSS file is pretty straight forward:

body {
background:#eee;
text-align:left;
color:#666;
width:700px;
font-size:16px;
font-family:georgia, 'time new romans', serif;
margin:0 auto;
padding:0;
}

h1 {
font-size:46px;
font-family:'Trebuchet MS', helvetica, arial, sans-serif;
letter-spacing:-1px;
color:#000;
font-weight:400;
padding:20px 0 0;
}

h2 {
font-size: 34px;
font-family: 'Trebuchet MS', helvetica, arial, sans-serif;
color:#21211f;
font-weight: 400;
padding: 20px 0 10px; 0
}

h3 {
font-size:14px;
font-family:verdana, helvetica, arial, sans-serif;
letter-spacing:-1px;
color:#fff;
font-weight:400;
text-transform:uppercase;
margin:0;
padding:8px 0 8px 15px;
}

p {
color:#aaa;
font-style:italic;
line-height:22px;
padding:0 0 30px;
}

img {
border:none;
}

.content {
margin:10px 0 50px;
padding:0;
}

.content p {
font-style:normal;
font-family:helvetica, arial, verdana, sans-serif;
color:#676767;
background:#fff;
border:1px solid #fff;
-moz-border-radius:5px;
-webkit-border-radius:5px;
margin:35px 0;
padding:20px;
}

.megamenu {
background:#9FC54E;
border:1px solid #9FC54E;
-moz-border-radius:5px;
-webkit-border-radius:5px;
font-family:helvetica, arial, sans-serif;
font-size:24px;
width:698px;
height:60px;
color:#FFF;
margin:0;
padding:0;
}

.megamenu ul {
text-align:center;
list-style-type:none;
margin:0;
padding:16px;
}

.megamenu ul li {
list-style-type:none;
display:inline;
margin:0;
padding:0;
}

.megamenu ul li a,.megamenu ul li a:visited {
text-decoration:none;
color:#fff;
margin:0;
padding:10px;
}

.megamenu ul li a:hover,.megamenu ul li a:visited:hover {
text-decoration:none;
color:#CEFF65;
margin:0;
padding:10px;
}

.megamenu ul li.downservices {
background:url(images/arrow.png) 100% 55% no-repeat;
margin:0;
padding:10px 8px 10px 10px;
}

.servicesdropped {
display:none;
text-align:left;
position:absolute;
background:#172323;
font-size:12px;
width:590px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border:1px solid #000;
margin:10px 0 0 20px;
padding:10px 20px 20px;
}

.servicesdropped p.textleft {
float:left;
font-size:12px;
width:200px;
margin:10px 0 0;
padding:0 20px 15px 10px;
}

.servicesdropped ul.middle {
text-align:left;
float:left;
border-right:1px solid #333;
border-left:1px solid #333;
font-size:12px;
width:180px;
margin:0;
padding:0;
}

.servicesdropped ul.right {
text-align:left;
float:left;
font-size:12px;
width:178px;
margin:0;
padding:0;
}

.servicesdropped ul.right li a,.servicesdropped ul.middle li a {
list-style-type:none;
display:block;
color:#888;
font-size:12px;
margin:0;
padding:5px 0 5px 20px;
}

.servicesdropped ul.right li a:hover,.servicesdropped ul.middle li a:hover {
list-style-type:none;
color:#9FC54E;
display:block;
font-size:12px;
margin:0;
padding:5px 0 5px 21px;
}

Our rounded corners are styled using the border-radius property (the W3C validator doesn’t like this, but it looks good and doesn’t impact usability at all). Something like this:

border:1px solid #000;
-moz-border-radius:5px;
-webkit-border-radius:5px;

Of course I changed the border color to match the color of my divs and paragraphs. The rounded corners won’t work in IE6, but does it really matter? :)

Working Demo And Download

Please have a look at the demo to have a better idea of how the menu will work:

You can also download a zip file containing the files from this tutorial:

I hope you enjoyed this tutorial, please let me know what you think!

A websites’ structure from A to Z

You created a great design for you website but now you’re not sure how to start coding it? How to structure it? How do you use CSS to display that beautiful design in the browser? Well… this tutorial should answer all those questions.

A mock-up

A rather simple design for the company Simple Designs.

Mock-Up

Visualizing the structure

Now with a design in mind, you should see 5 sections: Branding, Navigation, Content, Sidebar and Site Info.

Mock-Up

Start with the mark-up

< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">



You'll notice that I kept the same titles we used to define our sections in the HTML. Most often than not, you will see designers use HEADER instead of BRANDING but BRANDING is a much more meaningful word that describes the content for this div. Same reasoning with SITEINFO. Many use FOOTER but what's in a footer? Site information is usually in there like address or phone numbers or just more information pertaining to the site. Always try to be as descriptive as possible when creating your sections (ID)

Now that we have our structure skeleton all checked, let's add the content.

< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">


Simple Designs

A web design portfolio by Karinne Legault

I create clean, simple and usable websites for small business and organizations

This is my web design portfolio.

I'm a designer and a coder. I can create a site from an idea or take an existing site and make it more accessible and search engine friendly without costing you an arm and a leg.

Have a look around and contact me when you're ready. Hopefully I can help you get the idea
from your mind onto the web.

Latest additions to the portfolio

"Company
"Company
"Company

A little bit about me

Hello! My name is Karinne Legault. I'm a web designer by day and a ... well I need my beauty sleep so ... I sleep at night. Want to know more?

Lately on Simple Designs

Welcome to the new version of Simple Designs. We are quite happy with this new layout.Please ... let us know what you think of it.

Tuesday, November 6th, 2007

Out with the old and in with the new! Just launched is the snew site for Company A. A great new design to complement the new energy from their new CEO.

Friday, October 26th, 2007

Copyright © 2007 Karinne Legault

Proudly hosted by HostingCompany


If you copy all that code and open it up in your favourite browser, you should basically see what a person on a screen reader will see: content.

Mock-Up

While it's not pretty, it serves its purpose. With the headings in place, once can look at the content and discern the areas and read the website like a book.

Let's style it!

We will be putting all our styles in a separate stylesheet called styles.css so let's add a link to this in the of our HTML document

Now we'll dive in and start setting up the basic styling for our site.

  1. We want to remove the default margins and padding set by the browser.
  2. We want to use Verdana as the main font for the content and set it as 12px.
  3. We want links to be bold, underline and with color #4ecdc4 and not underline when on hover state.
  4. Assign the different size and colors to the different headings used throughout the site.
/*** COMMON ELEMENTS
********************************/

html, body {
    margin: 0;
    padding: 0;
}

body {
    font: 12px Verdana, Geneva, sans-serif;
    background-color: #fff;
}

a:link, a:visited, a:active {
    color: #4ecdc4;
    font-weight: bold;
    text-decoration: underline;
}

a:hover {
    text-decoration: none;
}

h2 {
    color: #556270;
    font-size: 24px;
}

h3 {
    color: #c44d58;
    font-size: 18px;
}

h4 {
    color: #c44d58;
    font-size: 14px;
}
Mock-Up

Now that we've settled the basic styling for our common elements, we'll tackle each section individually.

One thing you notice when you look at the mock-up provided; there are a lot of colors and bars and big backgrounds, etc... but all this design will be using is 4 images. The rest will be set in the CSS.

BRANDING

Our branding will use the nice image to display the company name and slogan so we need to add that image in our HTML

"Simple

Simple Designs

A web design portfolio by Karinne Legault

Now we need to hide the

and

by setting the two elements to position: absolute; and giving them a text-indent: -9999px;. This method was first introduced by Mike Rundle back in August of 2003 and I believe it to be the most accessible image replacement.

/*** BRANDING
********************************/

#branding {
    background: #fff url(../i/branding-bg.jpg) repeat-x 0 0;
    height: 118px; /* 142px */
    padding-top: 24px;
    overflow: hidden;
}

#branding h1, #branding h2 {
    position: absolute;
    text-indent : -9999px;
}
Mock-Up

NAVIGATION

We will be using a list to display the navigation. As explained by Mark Newhouse in his Taming List article from A List Apart magazine:

These are often marked up as a string of links, often in separate DIVs or paragraphs. Structurally, however, they are a list of links, and should be marked up as such.

And the CSS:

/*** NAVIGATION
********************************/

#navigation {
    background: #fff url(../i/navigation-bg.jpg) repeat-x 0 0;
    height: 65px;
}

#navigation ul {
    margin: 0;
    padding: 0 0 0 15px;
    list-style: none;
}

#navigation ul li {
    float: left;
    display: inline;
    padding-right: 10px;
}

#navigation ul li a {
    height: 29px;
    min-width: 10px;
    color: #000;
    font-size: 18px;
    font-weight: normal;
    letter-spacing: 1px;
    text-decoration: none;
    display: block;
    padding: 6px 7px 0;
}

#navigation ul li a:hover {
    background-color: #7fefe7;
}

In the #navigation ul { }, the list-style: none; property is what removed the bullets from the unordered list element. display: inline; and float: left; will set the list elements to display in a line.

A simple hack

If you look at the present site in Internet Explorer 6, you will notice that the navigation is not displaying inline. This is because IE6 does not support the min-width property. We need to add width: 10px; property for IE6 and we will do this by using conditional comments.

Add this in the of your document

/*** NAVIGATION
********************************/

#navigation ul li a {
width: 10px;
}
Mock-Up

CONTENT

Before we start we will add a #content_wrapper div to contain both the #content and the #sidebar div to limit the space used to 780px.

...

...

/*** CONTENT - WRAPPER
********************************/

#content_wrapper {
width: 760px;
overflow: hidden;
padding: 0 10px;
}

The overflow: hidden; property is there to clear the floats:

A common problem with float-based layouts is that the floats' container doesn't want to stretch up to accommodate the floats. If you want to add, say, a border around all floats (ie. a border around the container) you'll have to command the browsers somehow to stretch up the container all the way.

The CONTENT and SIDEBAR area are side by side. We will be floating both of them; one left and one right. Never use absolute positioning or relative positioning for such simple tasks. The float property is much simpler.

/*** CONTENT
********************************/
#content {
    float: left;
    width: 480px;
}

/*** SIDEBAR
********************************/
#sidebar {
    float: right;
    width: 230px;
}
Mock-Up

Pretty simple huh? Hang in there... we're almost done!

SITE INFO

For the site info, we will do the same thing with did with the CONTENT section and that is add a #siteinfo_wrapper to contain the information in a 780px box.

...
...

Since we've already declared this information for the #content_wrapper, we will just add in the #siteinfo_wrapper to the declaration.

/*** WRAPPERS
********************************/

#content_wrapper, #siteinfo_wrapper {
    width: 760px;
    overflow: hidden;
    padding: 0 10px;
}

As with the content section we have 2 areas that we will float; again... one left and one right.

/*** SITE INFO
********************************/
#siteinfo {
    background: #fff url(../i/siteinfo-bg.jpg) repeat-x 0 0;
    height: 70px;
    color: #fff;
    font-size: 11px;
    margin-top: 15px;
}

#siteinfo .one {
    float: left;
    width: 480px;
    padding-top: 18px;
}

#siteinfo .two {
    float: right;
    width: 230px;
    padding-top: 18px;
}

We also have added a supplementary navigation to the SITE INFO that we have put in a list again.

Copyright © 2008 Karinne Legault

Proudly hosted by HostingCompany

And the CSS should look like this

ul.sup_nav {
    margin: 0;
    padding: 0;
    list-style: none;
}

ul.sup_nav li {
    display: inline;
    border-right: 1px solid #fff;
    margin-right: 10px;
    padding-right: 10px;
}

The colors of the links need to change from the turquoise to white.

#siteinfo a:link, #siteinfo a:visited, #siteinfo a:active {
    color: #fff;
    font-weight: bold;
    text-decoration: underline;
}

#siteinfo a:hover {
    text-decoration: none;
}

We're done!

Mock-Up

SOME EXTRAS

Notice that this doesn't exactly look like the original mock-up; the portfolio boxes are still one under the other, it's missing that pink "About" box and the green background for the date so... if you have some time, here's the code to get all those things sorted.

Portfolio boxes

This is a simple matter of floating each of them

.portfolio {
    float: left;
    width: 145px;
    height: 105px;
    margin-right: 5px;
}

.portfolio a:link img {
    border: 1px solid #4ecdc4;
}
Mock-Up

The big pink "About" box

By simply adding a background and some padding to the div containing the "About" info, you can make simple things like this stand out

#sidebar .short_about {
    background-color: #ff6b6b;
    padding: 8px;
}

.short_about h4 {
    color: #000;
    margin: 0;
}

.short_about a {
    color: #000;
}

.short_about a:hover {
    text-decoration: none;
}

We've also changed the color of the heading and link color

Mock-Up

Green background for dates

Again, just adding some background here

.latest_dates {
    background-color: #c7f464;
    font-size: 9px;
}
Mock-Up

Conclusion

Creating the mark-up is the most important factor here. Once you have it defined perfectly, you can change the look of a site without even diving into the HTML.

A perfect example of this is the CSS Zen Garden. Every design uses the exact same HTML file. Only a different CSS stylesheet (and accompanying images) are loaded.

Happy coding!

Demo/Downloads