Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,382 Programmers. There are 1,377 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

CSS pretty Horizontal and Vertical Menus

2 Pages V  1 2 >  
Reply to this topicStart new topic

> CSS pretty Horizontal and Vertical Menus

Rating  5
supersssweety
Group Icon



post 18 Sep, 2007 - 01:44 PM
Post #1


Rollover menus are all the rage. I can't stand a menu that doesn't rollover * cough * To me it is just feels icky when I mouse over a menu item and nothing happens. CSS makes pretty menus quite easy. Today we are going to learn how to make horizontal and vertical menus that are pretty and creative smile.gif Let's get started.

First I will show you the basics with a horizontal menu, so lets make a list:

CODE

<div id="menu1">
<ul>
   <li><a href="#">Freaking</a></li>
   <li><a href="#">Pretty</a></li>
   <li><a href="#">CSS</a></li>
   <li><a href="#">Menu</a></li>
   <li><a href="#">Just</a></li>
   <li><a href="#">For</a></li>
   <li><a href="#">You</a></li>
</ul>  
</div>


Easy enough. Now let's start off with the basics for a horizontal menu:

CODE

#menu1{
    height:25px;
    font-family:Verdana, Arial, Helvetica, sans-serif;
}
#menu1 ul{
    margin:0;
    padding:0;
    list-style-type:none;
}
#menu1 ul li{
    display:inline;
}
#menu1 ul li a{
    text-decoration:none;
    float:left;
    height:25;
    margin:12px 0;
    padding:15px;
    width:65px;
    text-align:center;
}


IPB Image

Well thats nice but it sure is ugly! Let's make it pretty now...time to go to photoshop...don't freak out it is the easiest step: Make a new file that is 25px in height and 3px in width:

IPB Image

Pick any two colors you like, put one on the forground and one on the background. I am going to go with dream-in-code orange. Now get your gradient tool, make sure the gradient is set on foreground to background:

IPB Image

Now make a line from the top to bottom and save it for the web in your images folder:

IPB Image

Now make a line from the bottom to the top and do the same:

IPB Image

Now here add this to your CSS, using your own image names:

CODE

#menu1 a:link, #menu1 a:visited{
    color:#fff;
    background-image:url(images/link.gif);
    background-repeat:repeat-x;
    background-position:center;
}
#menu1 a:hover, #menu1 a:active{
    color:#000;
    background-image:url(images/hover.gif);
    background-repeat:repeat-x;
    background-position:center;
}



Still not good enough for ya? OK let's spruce it up a bit with a border:

CODE

#menu1 a:link, #menu1 a:visited{
    color:#fff;
    background-image:url(images/link.gif);
    background-repeat:repeat-x;
    background-position:center;
    border: 1px solid #f16b12;
}
#menu1 a:hover, #menu1 a:active{
    color:#000;
    background-image:url(images/hover.gif);
    background-repeat:repeat-x;
    background-position:center;
    border: 1px solid #e89642;
}


IPB Image

Wow!!! Pretty!!...as pretty as orange can be...ok let's make a vertical one, use the same unordered list and here is the basic CSS for the vertical menu:

CODE

#menu2{
    padding:24px;
    font-family:Verdana, Arial, Helvetica, sans-serif;
}
#menu2 ul {
    margin:0px;
    padding:0px;
    list-style-type:none;
}
#menu2 ul li{
    padding:0;    
}
#menu2 ul li a{
    display: block;
    width:150px;
    height:30px;
    margin:0;
    padding: 10px;
    text-decoration:none;
    text-align:right;
}


But we need to make it pretty now! Go to photoshop and do the same as before only make the width the same as your ul li a width + padding on each side = 170 and make the height 3px, then take your gradient from right to left and then left to right. Then add this to your CSS:

CODE

#menu2 a:link, #menu2 a:visited{
    color:#fff;
    background-image:url(images/link2.gif);
    background-repeat:repeat-y;
    background-position:center;
    border: 1px solid #f16b12; /* this border doesn't work in IE6 */
}
#menu2 a:hover, #menu2 a:active{
    color:#000;
    background-image:url(images/hover2.gif);
    background-repeat:repeat-y;
    background-position:center;
    border: 1px solid #e89642;
}


The possibilities are endless, you can play with margins, padding, color, borders-- just remember DON'T mess with the ul margins and don't cop out w/ the a's you MUST have them in this order link, visited, hover, active. Otherwise they won't work properly. Let me know how it goes!

You can see these menus at: http://www.webtestinglab.com/tutorials/


Register to Make This Ad Go Away!

William_Wilson
Group Icon



post 18 Sep, 2007 - 07:07 PM
Post #2
Excellent explanation, and an example page too!

+1 for good use of the word Freaking.

jayman9
Group Icon



post 18 Sep, 2007 - 08:24 PM
Post #3
Very nicely done! Good work.

skyhawk133
Group Icon



post 18 Sep, 2007 - 08:42 PM
Post #4
What's wrong with orange?! blink.gif tongue.gif

supersssweety
Group Icon



post 19 Sep, 2007 - 07:13 AM
Post #5
awww thank you guys...

I knew I couldn't use the alternative to freakin wink2.gif

I am a fan of all colors, even the ugliest color can look good if it is complemented right, and the orange on this site is done well, I don't think any other color would do, it is unique enough to constitute a brand, I get a nice warm fuzzy feeling from it when I visit the site and when I see the color I will always associate it w/ </dream.in.code> haha but orange is just one of those colors that only fit well in certain situations, it is hard to make it work wink2.gif but works perfectly for this site

ahmad_511
Group Icon



post 19 Sep, 2007 - 01:45 PM
Post #6
Good one, you encourage me to finish my tutorial.
Regards.

smdesignworks
*



post 20 Sep, 2007 - 09:02 PM
Post #7
Essentially you could even make it better by using the "CSS Sprite" technique to put both those images on a single image file and just make the CSS move the positioning of the image down. I believe (or have read) that it makes the hover more responsive which means faster, and also instead of 2 menu images, its just one and would have a tiny bit less of a file size (I guess this is because it only needs 1 color palette instead of 2), so its even that much faster. Not to mention its so much cleaner when you have less images in your image folder, just one aspect of being extremely organized. smile.gif

supersssweety
Group Icon



post 21 Sep, 2007 - 11:37 AM
Post #8
QUOTE(smdesignworks @ 20 Sep, 2007 - 09:02 PM) *

Essentially you could even make it better by using the "CSS Sprite" technique to put both those images on a single image file and just make the CSS move the positioning of the image down. I believe (or have read) that it makes the hover more responsive which means faster, and also instead of 2 menu images, its just one and would have a tiny bit less of a file size (I guess this is because it only needs 1 color palette instead of 2), so its even that much faster. Not to mention its so much cleaner when you have less images in your image folder, just one aspect of being extremely organized. smile.gif


hrm that is a valid point, i'll have to google that one

skyhawk133
Group Icon



post 21 Sep, 2007 - 11:39 AM
Post #9
QUOTE(smdesignworks @ 20 Sep, 2007 - 10:02 PM) *

Essentially you could even make it better by using the "CSS Sprite" technique to put both those images on a single image file and just make the CSS move the positioning of the image down. I believe (or have read) that it makes the hover more responsive which means faster, and also instead of 2 menu images, its just one and would have a tiny bit less of a file size (I guess this is because it only needs 1 color palette instead of 2), so its even that much faster. Not to mention its so much cleaner when you have less images in your image folder, just one aspect of being extremely organized. smile.gif


Interesting, never thought of doing that but it makes complete sense.

supersssweety
Group Icon



post 21 Sep, 2007 - 12:09 PM
Post #10
found something...very interesting...

http://www.alistapart.com/articles/sprites

axel
Group Icon



post 21 Sep, 2007 - 01:07 PM
Post #11
Ugh I'm no good at this. Ok so here is my code. It is not looking like yours at all. crazy.gif

CODE

<!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>
<link rel="stylesheet" type="text/css" href="redefine.css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<div id="menu1">
<ul>
   <li><a href="#">Electric</a></li>
   <li><a href="#">Acoustic</a></li>
   <li><a href="#">Amps</a></li>
   <li><a href="#">Other Sites</a></li>
</ul>  
</div>


</body>
</html>



and here is the CSS

CODE


#menu1{
    height:25px;
    font-family:Verdana, Arial, Helvetica, sans-serif;
}
#menu1 ul{
    margin:0;
    padding:0;
    list-style-type:none;
}
#menu1 ul li{
    display:inline;
}
#menu1 ul li a{
    text-decoration:none;
    float:left;
    height:25;
    margin:12px 0;
    padding:15px;
    width:65px;
    text-align:center;
}

#menu1 a:link, #menu1 a:visited{
    color:#fff;
    background-image:url(../Images/menu2.jpg);
    background-repeat:repeat-x;
    background-position:center;
}
#menu1 a:hover, #menu1 a:active{
    color:#000;
    background-image: url(../Images/menu1.jpg);
    background-repeat:repeat-x;
    background-position:center;
    border: 1px solid #e89642;
}



What's going on? sad.gif

supersssweety
Group Icon



post 21 Sep, 2007 - 02:11 PM
Post #12
Is the "other sites" dropping down? This is what it does for me when I pasted your code in my testing lab...I tried positioning the background to the top for the a lvha and that helped a little.....let me keep tweaking it...it is the fact that it is on two line, I even tried to put a br in it, and that didn't work either...let me keep tweaking and see...


2 Pages V  1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 5/17/08 03:40AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month