Subscribe Via RSS

3910 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 Stars113 Votes, Rating: 4.59
Loading ... Loading ...

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.

About The Author

About The Author: Richard Carpenter

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

 

Richard Carpenter has written 364 posts.

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

156 Responses to “CSS Menu With Icons”

  1. Ian says:

    Very nice and well explained tutorial, but I would have combined the icon images into one sprite and used positioning for displaying the correct icon.

    PS if you need a proof reader to correct what your spell checker misses contact me!!

  2. ayitfals says:

    Photoshop and Notepad++ the great software for me.
    very-very nice tutorial because I’m just a beginner for CSS coding.

  3. amine says:

    i love you man, you are the greatest
    thx for all those tutorials

  4. fei says:

    thx,very cool

  5. Very nice tut – easy to understand – I’ll definitely be trying this one out in the near future.

    Thx m8!

    /3jerregaard

  6. askar says:

    Nice tutorial,but i stuck in this line:
    “Make each seperate image 300 pixels wide” in this step
    “you may need to stretch your mouse over line over more so it fits like the image below.”
    in this line. please reply , thx

  7. dyrer says:

    I like this tutorial but i am new to photoshop and I can’t find all the options and what version PS are you using? I have CS4

  8. Very nicely done.

  9. Manuel says:

    Very nice tutorial.
    I just don’t understand what is in this part of code:

  10. vitmel says:

    Nice. I just don’t understand this line
    .navigation li a b
    You didn’t explain what is “b” or I missed something?

  11. thxx very coolll

  12. Gaurav says:

    which photoshop version have you used? i am using PSE 8 and these options are unavailable..

  13. kedar BHAI says:

    Bhai tu bhai fikar na kar uski maa ki uski ben tu fikar na kar

    nice works gr8t!!!

  14. cemo says:

    Nice menü tutorial.Thx

  15. colmy says:

    Very nice!
    i will use it later

  16. Alex says:

    Cool!

  17. Cilsilver says:

    you have always been an inspiration, RIchard. I found this useful for my present project. Jah Bless. Thanx

  18. Robert says:

    Hi Richard, I had a lot of trouble with CSS and making something like you showed here, I really have to say, GREAT! At least I have a perfect and good looking menu bar, ugh … Thank you and keep going, because you are doing a great job and are making our lives easier by your tutorials :)

    Thank you, Robert.

  19. Robert says:

    … looking much more better our stes we all trying to make. (sorry for mistakes ;)

  20. Robert says:

    Hi Richard …
    I have to say, really great tutorial. Thank you for this and keep going, because you helped me a lot by this one ;)

    Robert

  21. Robert says:

    Hi Richard,
    I would like to ask you, I was trying to use your tutorial for navbar, looks great, but there is appearing one problem, that is to say, if I open each site like “about, “gallery” etc etc , so current still staying home, how should I do that to change it …? Thank you, Robert (kvark@rocketmail.com)

  22. Aaron says:

    Robert, you will need to define the hyperlinks for each page. Instead of you will need to put replacing yoursitepage with the name of your page, ie gallery.html

  23. srinivas says:

    Hai Richard …
    I have to say, really great tutorial. Thank you for this and keep going, because you helped me a lot by this one ;)

    Srinivas

  24. virender says:

    very good . you must attach sample file

  25. Ahsan says:

    I m having trouble how ur in 2nd step because when i use gradient and stroke it doesn’t work on the area i have selected ……….. plz tell me how to use it on selected part ? plz because i m new to photoshop

  26. Aaron says:

    @Ashan: You will want to right click the new layer you create and choose Layer Styles and add the layer styles mentioned.

  27. Julius says:

    I can’t get pass the selection portion. “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.” I am using CS3, I am doing something wrong…please help.

  28. Nickolai says:

    That’s very nice.
    Good work.
    Thanks.

  29. Marvs says:

    great work on this rich..life gets easier for me.
    Thanks

  30. sergio says:

    Hi, excellent tutorial, I need help making a menu with css, I have a notion of code only offer that I get confused on some things, like my menu background is transparent and I want animation, for example when passing the cursor changes color the letter or something. Thanks in advance for your help

  31. Deepro says:

    hey, very very nice, but the photoshop version does not match…. so would you plz send me the zip file with source code…..it d b very kind of u and i ll b vry grateful 2 u…plz plz i need it badly man….waiting…

  32. Gershwin says:

    I can’t do this.. seriously.. it would have been better if you made a video tutorial.. like for e.g, you don’t say to make a new layer at the beginning. did you assume we would know that? there so many things that are not the same with different version..

  33. Karl says:

    Great work man, even if I’m not a photoshop pro, I just used some images I had and achieved almost the same effect.

    thanks

  34. ice says:

    Great presentation process and very butiful menu, i change my menu website away!

Leave a Reply