Subscribe Via RSS

3268 Subscribers

Subscribe Via RSS
Subscribe Via Twitter

Followers

Subscribe Via Twitter
CSS Menu With Icons

September 18th, 2008 in Coding Tutorials by Richard Carpenter

CSS Menu With Icons

1 Star2 Stars3 Stars4 Stars5 Stars80 Votes, Rating: 4.65
Loading ... Loading ...
About The Author

About The Author: Richard Carpenter

Hi im Richard Carpenter im a freelance web and graphics designer from England. I am also a regular Blogger, Tutorial Writer, and owner of HV-Designs. You can follow me on twitter HERE. You may also view my portfolio HERE.

 

Richard Carpenter has written 331 posts.

Hello, welcome to another tutorial by the hv-designs team, today we’ll be making a CSS menu with icons.

Firstly lets create our navigation in photoshop, create a new document 600×200 pixels with a black background. Create a rectangle 600×40 pixels with rectangular marquee tool, you can create specific sizes by changing the style to “fixed size”.

Fill your navigation with the color black then add these layer styles.

You should have something like this.

Select the rectangular marquee tool again and create a selection like this.

Fill with the color white, then click on your naviagtion layer whilst holding down the ctrl key on the key board to make a selection.

Once you have made the new selection goto, “select > inverse” then hit the delete key. You should be left with this.

Lower the opacity to about 5% then add your naviagtion text.

Now select the rounded rectangle tool and create a small rectangle next to your navigtation text. The icons should be no bigger than 32×32 pixels. Althou you can make them bigger if you want you just need to adjust the CSS code when we come to code it. Add these layer styles to each of your round rectangles.

Your navigation should now look like this.

Inside the round rectangles we want to add our icons, im going to use some preset shapes in the custom shapes libary that came free with photoshop. Once you have chosen your icons and added them inside the rectangles add this outer glow.

Your navigation should looks something like this.

Looks abit cramped up, but it doesnt matter as we can set the spacing of each item in css. For this bit we need to zoom in abit, select the pen tool with the color #008aff, draw a line underneath your 1st item.

Now add this layer style to your line.

Thats it for your naviagtion, you end result should be something like this.

Now that we’ve finished we need to slice our navigation up, so go ahead and create a new folder on your desktop called navigation, then inside that folder create another 2 folders called “icon_images” and “navigation”. Inside the “icon_images” folder we need to save each icon as seperate images dont forget they need to be 32×32 pixels and on a transparent background, save each of them as .PNG files. Heres mine.

We also need 2 chunks of our navigation one being the main background and the other one being the mouseover. Head back over to your naviagtion which should still be in photoshop, hide all your layers apart from your main navigation and the mouse over.

Make each seperate image 300 pixels wide, you may need to stretch your mouse over line over more so it fits like the image below. Save these 2 files as “nav_background” and “nav_hover”.

Next you need to create an empty text file and save it as styles.css in your root naviagtion folder. After you’ve done that its time to open dreamweaver. Create a new html document and straight away save it as index.html or whatever you want to call it save the file in your root folder with your styles.css file. Edit your title text and link your style sheet.

<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dt-->

After this bit of code we need to map out our navigation using the standard UL and LI tags which looks like this.

<ul class="navigation">
	<li class="current"><a href="http://www.hv-designs.co.uk"><em class="home"></em><strong>Home</strong></a></li>
	<li><a href="http://www.hv-designs.co.uk/hv_shop"><em class="templates"></em><strong>CSS Templates</strong></a></li>
	<li><a href="http://www.sb-designs.co.uk"><em class="psd"></em><strong>PSD>HTML</strong></a></li>
	<li><a href="http://www.hv-designs.co.uk"><em class="tutorials"></em><strong>Tutorials</strong></a></li>
	<li><a href="http://www.hv-designs.co.uk/hv_shop"><em class="shop"></em><strong>Shop</strong></a></li>
	<li><a href="http://www.hv-designs.co.uk"><em class="contact"></em><strong>Contact Me</strong></a></li>
</ul>

You will notice that next to each link there is a “EM CLASS” this will refer to our icons in the style sheet. You will also notice like the 1st navigation tutorial we have set “LI CLASS CURRENT” which basically means the link on the navigation will stay in mouseover state for that certain page.

So you HTML code should look like this.

<!--CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dt-->

 
<ul class="navigation">
	<li class="current"><a href="http://www.hv-designs.co.uk"><em class="home"></em><strong>Home</strong></a></li>
	<li><a href="http://www.hv-designs.co.uk/hv_shop"><em class="templates"></em><strong>CSS Templates</strong></a></li>
	<li><a href="http://www.sb-designs.co.uk"><em class="psd"></em><strong>PSD>HTML</strong></a></li>
	<li><a href="http://www.hv-designs.co.uk"><em class="tutorials"></em><strong>Tutorials</strong></a></li>
	<li><a href="http://www.hv-designs.co.uk/hv_shop"><em class="shop"></em><strong>Shop</strong></a></li>
	<li><a href="http://www.hv-designs.co.uk"><em class="contact"></em><strong>Contact Me</strong></a></li>
</ul>

Thats all the HTML code we need, so now head over to your styles.css file. At the top of your css file add a comment code, which looks like this /* NAVIGATION ELEMENTS */ after that we start to add our navigation css rules.

.navigation {
padding:0 0 0 20px;
margin:0;
list-style:none;
height:40px;
background:#1841c8 url(navigation/nav_background.gif);
}

padding:0 0 0 20px = A shorthand property for setting all of the padding properties in one declaration.
margin:0 = A shorthand property for setting the margin properties in one declaration.
list-style:none = removes the bullets from the list.
height:40px = height of our navigation bar.
background:#000000 url(navigation/nav_background.gif) = sets our naviagtion background color to black, and also sets the background of our navigation which refers to our image we created in photoshop.

Our next bit of css code is.

.navigation li {
float:left;
}
.navigation li a {
display:block;
float:left;
height:40px;
line-height:40px;
color:#FFFFFF;
text-decoration:none;
font-family:arial, verdana, sans-serif;
text-align:center;
padding:0 0 0 10px;
font-size:11px;
}
.navigation li a b {
	float:left;
	display:block;
	padding:0 16px 0 8px;
}

float:left = The float property sets where an image or a text will appear in another element. In our case left.
display:block = The element will be displayed as a block-level element, with a line break before and after the element.
line-height:40px = The line-height property sets the distance between lines.
color:#FFFFFF = Color #ffffff is white.
text-decoration:none = Defines normal text.

The next bit of css defines our “current” class and “mouseover” image.

.navigation li.current a {
	color:#FFFFFF;
	background:url(navigation/nav_hover.gif);
}
.navigation li a:hover {
	color:#00CCFF;
	background: url(navigation/nav_hover.gif);
}
.navigation li a em {
	display:block;
	float:left;
	width:30px;
	height:40px;
}

Take note of the background: URL as the links relate to our mouse over image we created in photoshop. Also double check your image paths which is something i should of mentioned ealier, if you images dont show when we text in the browser then more than likely it will be the image path.

The last bit off css code is for our icons. Again dont for get to comment code /* ICON ELEMENTS */.

/* ICON ELEMENTS */

.navigation li a em.home {
	background-image: url(nav_icons/home.png);
	background-repeat: no-repeat;
	background-position: center center;
}
.navigation li a em.templates {
	background-image: url(nav_icons/templates.png);
	background-repeat: no-repeat;
	background-position: center center;
}
.navigation li a em.psd {
	background-image: url(nav_icons/psd.png);
	background-repeat: no-repeat;
	background-position: center center;
}
.navigation li a em.tutorials {
	background-image: url(nav_icons/tutorials.png);
	background-repeat: no-repeat;
	background-position: center center;
}
.navigation li a em.shop {
	background-image: url(nav_icons/shop.png);
	background-repeat: no-repeat;
	background-position: center center;
}
.navigation li a em.contact {
	background-image: url(nav_icons/contact.png);
	background-repeat: no-repeat;
	background-position: center center;
}

Were only setting 3 simple rules for each of our icons as most of the important stuff is inherited from the other CSS RULES. The most important again is our individual images or icons that we made previously. If you look at our HTML code in our links you will see each icon has its own individual class that relates to there own snippet of code in the css file.

Be Part Of The Community!

Become part of the hv-designs community.

Subscribe Via RSS or Follow Us On Twitter.

Subscribe Via RSS Follow Us On Twitter

117 Responses to “CSS Menu With Icons”

  1. Elliot says:

    <3 10/10

  2. Victor says:

    another great tutorial

    thanks :D

  3. Neil says:

    Not a bad tutorial matey

  4. nolimitTM says:

    CooL

  5. Dan says:

    Good tutorial, thanks

  6. Jacob says:

    Excellent work Richard. keep up the effort.

    Jacob.

  7. Sky - Des says:

    Great :d

  8. sagar says:

    Grt work, and in a very easy way.
    Keep it up

  9. Great Tutorial, but I’m having trouble over here on my end. I followed each step but for some reason when I view my index page in my web browser my icon and nav background images will not show.

  10. ADMIN says:

    double check your image paths

  11. greg says:

    i folwed it to but i have the same problem as teh guy above.

    http://darkhybrid.com/navigation/

    what have I done wrong? cheers

    great website btw

  12. ADMIN says:

    if the images are not showing then you need to double check your image paths.

  13. greg says:

    i have double checked them over and over again but nothing..

  14. ADMIN says:

    zip it up and send to
    webmaster@hv-designs.co.uk

    and il have alook

  15. Nice Css tab example thanks man.

    I will use this on my website to get a new fresh look

  16. daire 'dumbass' kid says:

    Hi great tut, I’m shit at working photoshop and i dont know where to find the icons u used. i looked in the brush library but no dice. how i find them?

    sorry for idiot question

  17. Stalin Selvam says:

    Nice tutorial for creating the menubar, can you please help me on creating dropdowns to those buttons.. or leading to any of tutorials which has icons and dropdown menu. Thanks

  18. ADMIN says:

    the icons are found in the custom shapes libary its the icon underneath the “path selection tool”

    its bunched up with a few other things “rounded rectangle tool”

  19. a.design says:

    I have the same problem, the navigation does’nt show the images, just words..

  20. webthese says:

    Nice tutorial. I really like your design.

  21. ADMIN says:

    i forget to mentuon in the tutorial about linking the stylesheet . :(

    link your style sheet in the html file and should be ok

  22. meshael says:

    a really Nice tutorial. thanx

    a.design: u have to connect the index file with the css file by adding:

    between head tags..

  23. Rabia Balagam says:

    Very nice tutorial..Thanks

  24. YahooBot says:

    Nice site, thanks for information!

  25. novackus says:

    Very cool. 5/5

  26. Nexx says:

    I got a lil’ problem. Im trying to put this stuff in something different and trying to mix them, but hover isnt working. I see only the little image like behind the text. I tryed to change padding but it moves link then. So, what to do?

  27. Shasta says:

    I’m a bit confused when your slicing up the hover images, making each selection 300 pixels wide would be half the nav bar, they would not look like tutorial, is this a mistake? Great tutorial however, maybe I’m just confused.

    Thanks.

  28. ADMIN says:

    300 pixels aint the width of the actual button on the navbar, but if you have a long word like “website templates” for example, then 300pixels will be long enough for the text to fit.

  29. Shasta says:

    Ok figured out most but after doing some tweaks how does one align the hover image under the corresponding link. After resizing and modifying the glow is now a tad off, i’ve been messing with the padding but it only seems to shift the text and image buttons but not successful with moving the hover. Thanks

  30. Joe says:

    Hi,

    Good tutorial. I just can’t get it work though. I’ve bought it and extracted all the files, so I know the coding’s right.

    When I try to view it, it doesn’t show any images.

  31. ADMIN says:

    double check your image paths / folders …. incorrect paths are often the cause for non displaying images

  32. Joe says:

    I’ve downloaded the files and images.

  33. ADMIN says:

    the images should work, ive just tested it my end everything is hunky dory.

  34. Joe says:

    You want me to send you images of what I get? So you can understand better?

  35. ADMIN says:

    Use “contact” button very top of page. :)

    also explain what it is,… is going wrong

  36. Shasta says:

    Just wanted to thank you for providing such a great tutorial. I’ve been banging my head trying to get out of the old school methods of tables and what not and really got a good handle on CSS just from this tutorial. From your tutorial I have so far created my first truly CSS website, some may think not a big deal but too me not relying on a tables for aligning everything has been a god send. I’m no expert but it looks pretty good and quite frankly surprised myself. I did manage to cheat the hover by slicing more to the left to give the illusion the glow is under each heading correctly, no one will be the wiser, wait a minute the cats out of the bag, as long as the boss doesn’t know, lol.

    Great write up.

  37. WebGlad says:

    Extremely cool tutorial. I am definitely going to rock the css with icons nav. Thanks for sharing with everyone!

  38. thanks for the very detailed tutorial :)

  39. Shasta says:

    I’ve been experimenting with this tutorial just to help understand how everything works together but compatibility issues have stumped me. I’ve managed to center the menu on a fixed layout in Safari and Firefox with no problem but when its viewed in Internet Explorer its shifted to the left, how would you center float this menu system in IE?

  40. Thx!!!!!!! It’s cool tutorial & you sait….!!!

  41. z4ro08 says:

    Wow.. I like it so much, thks for the info

  42. Chapa ilale says:

    Thanks

    I hav a “but”

    It aint working, Even after just copying the whole “tut” I’ve double checked the image paths

  43. DHPD says:

    i get one icon (the faq icon) not showing up..
    the rest does show up
    i double checked the paths in it seems alright…
    also the icons are on the navigation hover (the grey stroke and the blue line)
    and the blue line stays on the forum icon (in your case home icon) , it doesnt go away

    ( o yeah i copied your whole css tutorial and changed it a bit to fit in my lay-out but i can use this lay-out on another site?)

  44. DHPD says:

    also the icons are on the navigation hover (the grey stroke and the blue line) <..<

    and the blue line stays on the forum icon (in your case home icon) , it doesnt go away <..<

  45. DHPD says:

    Ok

    i made this navigation first and then i coded my layout to html but when i did i didnt include the navigation bar so now i have two types of index the weblayout and the navigation.
    now i want to combine them , how do i do that?

  46. ADMIN says:

    just copy/paste the code over and CSS, just make sure you have sufficient space for your nav regarding the width etc…, really you should of coded it as one ;)

  47. DHPD says:

    Ok i did that but now i have the navigation bar on the top right corner of my screen..
    while it supposed to be like this >.>
    [img]http://img168.imageshack.us/img168/7016/weblayoutcopy.png[/img]

  48. Nxz says:

    Good Tut..

  49. rio says:

    awwsome tutorial!!

  50. Excellent tutorial! I love the icons and the glowing effect is absolutely amazing. Thanks for taking the time to post this very thorough tutorial, keep up the good work!

  51. NoOne says:

    hi
    congratulation….!
    thanks we call a JOB amigo
    very good and thanks for this perl :)

  52. This has to be one of the most beautiful menus I have yet seen; and I would dearly love to emulate it as I attempt to re-write the Web site for the local affiliate of Habitat for Humanity, a non-profit organization.

    I have considered myself reasonably proficient in Photoshop, but in at least two places, I am completely stymied. Does this tutorial assume CS4? I have CS2. I wish to change the colors to Habitat’s official colors and, of course, all the icons. I know I am asking an awful lot, but is it possible for you to send me your original PSD with all the layers, etc., accessible? I really feel embarrassed asking this, but I am teaching myself Web site management for them, and this is simply making it that much more difficult. I would hate to have to use a simpler, but plainer, Navigation bar.

    Regards,

    Jack

  53. great tutorial! (will be included next weel as link in article at http://blog.metuzalem.hr that more people can see it)

  54. Shailendra says:

    Hello admin ,
    First , it is a great Tut, mearging photoshop , html and CSS..thanks a lot ..i can imagine how much time you have dedicated for this. ..thanks.

    I need help on 2 things

    1. How to save each icon as seperate images (32*32) with transparent background ? *i am tried to hide layer and save the icon but the size is 600*400 (the orginal size of the platform.)*

    2.how to save the main background and the mouseover image ?
    Please describe the above 2 steps in details as i ( & many other) being new bees in photoshop.

  55. Shailendra says:

    i am doing a vertical navigation/menu ..how do i do it.?

  56. A great looking result. Thanks for showing us the way!

  57. Kirli Adam says:

    wonderfol :) l love you lessons… forever hv-design

  58. Thanks You…It’s a great Leasson :)

  59. Namegooder says:

    Thank You!

  60. Nameamber says:

    Once you have made the new selection goto, “select > inverse” then hit the delete key. You should be left with this. not working for meee….

  61. Nameamber says:

    i done all, very nice for learning. thanks a lot.

  62. HARSH says:

    hey nice tutorial.
    i reallt like it.
    Keep it up.

  63. Bav says:

    So glad I found this site! Will be trying this tutorial soon!

  64. mojitopl says:

    Thanks for the tutorial. The thing is brilliant. Though I had to change to in CSS (or You shoul’ve used in Your html mark-up). It;s working great and lets lots of flexibility.

  65. Humza says:

    This is lovely

  66. PKM says:

    How to center this?

  67. MaMa says:

    how to save the icon to PNG ?

  68. yadirosadi says:

    nice tutorial. Thanks!

  69. Tobi says:

    I love this Tutorial ! Thanks !! 10/10

  70. Helam says:

    Hi.. that’s so cool tutorial… I was looked for something like that.
    Thanks Richard.!!

  71. Thomas says:

    This is an old tutorial :P maybe 2 years old. nice though that you gave it a new life ;)

  72. Abel says:

    Nice work mate but can you tell me how we can center the navigation.. I am not good in these stuff but i tried everything i could… Please help…if possible please reply to shazz248@yahoo.com

  73. sivakumar says:

    I like the style of menu Better we can try this and convert in to HTML

  74. clambyan says:

    Very Nice. Thank’s for Tutorial.

  75. devoria says:

    do you use dreamweaver for coding or what please help me richard

Leave a Reply