Search:
All Any

Part of mariaus.info network Subscribe via RSS
Follow on twitter Request a tutorial
25 Photoshop tricks that you should know
Neon water mushrooms
Visitor request: Advanced reflections in Photoshop
Create cloud brushes in Photoshop
Create a space nebula in Photoshop
Photography and art inspiration # 4
Photography and art inspiration # 1
Photography and art inspiration # 3
Photography and art inspiration # 2
Go to first pageAdd to favorites (this)Contact page ownerRequest a tutorialSubscribe to the Tip Kit news
Request a tutorial
Create a cool web 2.0 navigation bar

Learn how to create a cool navigation bar in Photoshop and code it in HTML, CSS and JavaScript.
Today we're be designing a cool looking navigation bar and converting it into a fully functional item with HTML, CSS and JavaScript. Have a look at the demo below.

Demo (hover your mouse cursor over the buttons)



Part 1 - Design in Photoshop

We will be creating a single 100x100 pixels document that will serve us as a template for the menu items. All the icons and captions will be integrated into one image. You may use GID, PNG or even high quality JPEG images to store your menu items in. In the demo above the images are stored as high quality JPEGs and, as you can see, they look pretty good. So let's start. Create a new 100x100 px document and set the color values as shown below:

img/p72_001.jpg

Now grab the gradient tool img/ps_tool_gradient.jpg from the tools palette and set it to be linear foreground-to-background:
img/p72_002.jpg

Draw a gradient from the top of the image to the bottom while holding SHIFT to force a straight line. You should end up with an image like this:

img/p72_003.jpg

Next, rename the layer to back or background and create a new one, named highlight. Go to Window > Info to open up an info panel. You will need this to draw a 50 pixels height rectangle. So grab the rectangular marquee tool img/ps_tool_selrect.jpg from the tools palette and draw a selection like shown below:

img/p72_004.jpg

Press D and X to set the foreground color to white, make sure highlight layer is selected and ALT+BACKSPACE to fill with white:

img/p72_005.jpg

Now set the highlight layer's opacity to about 20%. You should now have something like this:

img/p72_006.jpg

Create a new layer above the highlight and name it icon. Find yourself a PNG or other icon (use google or simply head on to this website and choose any icon from there). Paste your icon and resize it to fit in the document. Position it on the top of the image:

img/p72_007.jpg

Create a new layer above icon and name it text. Grab a text tool img/ps_tool_text.jpg from the tools palette and define some settings for the font. I've used the ones shown below:

img/p72_008.jpg

Set the foreground color to black (D on your keyboard) and click somewhere in the horizontal center of the document (make sure that text layer is selected). Type in a title for this button and position the text so that it looks best for you. Set its blending mode to multiply and double-click to add the following drop shadow style:

img/p72_009.jpg

Set the layer's fill to about 60% and you should now have something like this:

img/p72_010.jpg

We're done with our item. Now we need to create a splitter and a hover state image. Let's start with the hover. To do this, you need to grab the gradient tool, press D to set default colors and click on the gradient selection box:

img/p72_011.jpg

When the gradient editor dialog opens, you'll need to define a Fore-back-fore gradient. It's easy to do, just follow the steps below:

img/p72_012.jpg

img/p72_013.jpg

img/p72_014.jpg

img/p72_015.jpg

You should now have a new black-to-white-to-black gradient in your gradients list:

img/p72_016.jpg

It's not just a black-white-black gradient, the colors will automatically change as you change the background and foreground colors. We need this gradient so that we could mask some areas of the hover image and the splitter. You'll see this gradient in use in a second. So enough preparation, go ahead and create a new layer above highlight and name it hover. Press D to reset colors and ALT+BACKSPACE to fill the entire thing with black:

img/p72_017.jpg

It's pure black for now, but we'll fix it in a moment. And that's where our new gradient comes in: with the help of it and layer masks we're going to make the top and bottom parts of this black layer disappear. Click on a layer mask button img/ps_btn_mask.jpg in the layers panel to add a mask to the hover layer. Now grab a gradient tool with your newly created preset and draw a line from top to bottom while holding SHIFT to force a straight line. The result should be as shown below:

img/p72_018.jpg

Now we'll need to decrese the overall opacity since it's a little too dark. This part is entirely up to you. I've set the opacity to 55%:

img/p72_019.jpg

And you have your hover image. The last thing to do is create a splitter. To do that, disable all layers, except background and highlight by clicking on the eye icons next to them. Now create a new layer on top of everything else, name it splitter and grab a pen tool img/ps_tool_pencil.jpg from the tools palette. Set the foreground to black (D) and draw a vertical line while holding SHIFT:

img/p72_020.jpg

And now mask this line as you did with the hover layer: add a layer mask, select your gradient preset and draw the same vertical line on the mask. That's how your line looks now:

img/p72_021.jpg

It's still too dark so decrease the overall opacity of the layer to something that looks good to you. Mine is 50%:

img/p72_022.jpg

Next, grab the rectangular marquee tool img/ps_tool_selrect.jpg from the tools palette and draw a 1px wide selection around the splitter. You should zoom in a few times. Here's how the selection looks in a few hundred percent zoom:

img/p72_023.jpg

Press CTRL+SHIFT+C to copy the merged result to clipboard, then CTRL+N to create a new document and CTRL+V to paste the clipboard contents onto it. If you've done everything right, your new document will be 1x100px in dimensions and will now have the splitter on it. Save this document as splitter.jpg (or any other web file format) and you can close it. Make a new selection on your old document, but this time don't intersect it with the splitter. I've even disabled the splitter layer to do this:

img/p72_024.jpg

Once again, copy and paste it to a new document as you've just done and save the new document as loop.jpg. This will be our navigation bar background. So now we have a background, a splitter and all that's left to do is save ourselves a button itself. To do that, disable splitter and hover layers and enable all the others. Save the current document as btn1.jpg. Make sure you use 12 for the JPEG quality, because lower quality will probably look bad. You can use a PNG or GIF file instead if it looks better for you. Now enable the hover layer and save this document as btn1_h.jpg. The _h part tells us that it's a hover state image. And now you should have the following files saved in a single folder: loop.jpg, splitter.jpg, btn1.jpg, btn1_h.jpg. To add additional buttons, change the icon and the text and save both normal and hover states as you did with btn1 and btn1_h. The important thing is that the hover image must have the same name with _h appended at the end. For example about.jpg and about_h.jpg.

Part 2 - Coding the menu

Move all the images you've saved to a new folder, called images. First we'll need a navigation bar itself. It will be a 100px height DIV, defined as follows:

<div class="navbar">

</div>


The style for this navigation bar is as follows:

<style type="text/css">
.navbar {
    height: 100px;
    background: url(images/loop.jpg) repeat-x;
    margin: 0;
    padding: 0;
    text-align: center;
}
</style>


Change the value of text-align to left or right if you don't want your buttons centered. Let's add a first splitter:

<div class="navbar">
<img src="images/splitter.jpg" width="1" height="100" alt="" />
</div>


And now let's add our btn1 and another splitter:

<div class="navbar">
<img src="images/splitter.jpg" width="1" height="100" alt="" /><a href="URL GOES HERE"><img border="0" src="images/btn1.jpg" width="100" height="100" onmouseover="swapImg(this, 'images/btn1')" alt="" /></a><img src="images/splitter.jpg" width="1" height="100" alt="" />
</div>


Note that there can be no whitespace between <img> and <a> tags, because that will move our splitter away from the button. As you can see, we have an onmouseover event, that calls a swapImg function. It passes itself and an image address, without an extension to this function. And here's how the function looks like:

<script type="text/javascript">
function swapImg(pObj, pImg)
{
    pObj.src = pImg + '_h.jpg';
    pObj.onmouseout = function() {
        pObj.src = pImg + '.jpg';
    };
}
</script>



When you hover a mouse over btn1 image, this function appends an _h.jpg string to the image address and loads a hover image. It also defines the onmouseout function for the same button so that the image would change back when the mouse leaves. Below is the final result with 3 images. You should use external CSS and JS files in the real situation, however.

<html>
<head>
<style type="text/css">
.navbar {
    height: 100px;
    background: url(images/loop.jpg) repeat-x;
    margin: 0;
    padding: 0;
    text-align: center;
}
</style>
<script type="text/javascript">
function swapImg(pObj, pImg)
{
    pObj.src = pImg + '_h.jpg';
    pObj.onmouseout = function() {
        pObj.src = pImg + '.jpg';
    };
}
</script>
</head>
<body>
<div class="navbar">
<img src="images/splitter.jpg" width="1" height="100" alt="" /><a href="URL GOES HERE"><img border="0" src="images/btn1.jpg" width="100" height="100" onmouseover="swapImg(this, 'images/btn1')" alt="" /></a><img src="images/splitter.jpg" width="1" height="100" alt="" /><a href="URL 2 GOES HERE"><img border="0" src="images/btn2.jpg" width="100" height="100" onmouseover="swapImg(this, 'images/btn2')" alt="" /></a><img src="images/splitter.jpg" width="1" height="100" alt="" /><a href="URL 3 GOES HERE"><img border="0" src="images/btn3.jpg" width="100" height="100" onmouseover="swapImg(this, 'images/btn3')" alt="" /></a><img src="images/splitter.jpg" width="1" height="100" alt="" />
</div>
</body>
</html>


Article written by: Marius S.
This article is an intellectual property of its respective author. All images, used here are property of tip-kit.com if not stated otherwise.
Share this article
Digg del.icio.us Facebook Furl Google Reddit Slashdot StumbleUpon Technorati
How easy was it to understand? Was it useful?










Leave a reply
Your name:

Message:

Confirmation code
Please enter the above code:
matt says:
why would you use javascript for a simple navigation bar?
2009-08-17 14:50:36 (GMT)
Marius S. says:
Well, it's just another way of doing it. If i'm correct, IE6 wouldn't support a pure CSS solution.
2009-08-17 15:50:43 (GMT)
tanazsia says:
this stuff isnt any help can u gibve me anything else to work with
2009-10-12 18:08:32 (GMT)
Bjarke says:
You can make it work in IE6 with CSS and a little magic :D
2009-10-29 15:18:21 (GMT)
brandon says:
hey nice work any tutorials made should be appreciated. I easily gave this a 5 star. The graphics are nice and so is the coding. Keep making tuts for the rest of us that appreciate it.
2009-12-08 18:46:27 (GMT)
Copyright © 2009 Tip-Kit.Com | Valid XHTML 1.0 | Powered By Isis | RSS