Subscribe Via RSS

3927 Subscribers

Subscribe Via RSS
Subscribe Via Twitter

Followers

Subscribe Via Twitter
Carbon Fibre Style Inset Navigation: The Code

March 23rd, 2010 in Coding Tutorials by Richard Carpenter

Carbon Fibre Style Inset Navigation: The Code

1 Star2 Stars3 Stars4 Stars5 Stars10 Votes, Rating: 4.70
Loading ... Loading ...

Hello welcome to another tutorial by HV-Designs. In this tutorial il be showing you how to code the “Carbon Fibre Style Inset Menu” into a working CSS/HTML Document.

Follow Part 1

If you havent already created this navigation in photoshop you can do so by following PART 1 of the tutorial here.

View The Coded Version

You can view the full coded version here.

Coded Version

Setting Up Your Files

Before we even start slicing and dicing we first need to setup a few files. In a folder on your desktop you need a blank HTML file “index.HTML”, a blank CSS file “styles.CSS” inside another folder called “stylesheets”. Finally you need an empty folder for our images called “images”.

Inset Menu Coding Tutorial

The Markup

Open up your HTML file in your favorite code editor then within the “BODY” tag create a DIV ID of “container”. The container DIV will be our main container in which all our elements will be held.

<div id="container">
</div><!--CONTAINER ENDS-->

Inside the the “container DIV” create another DIV of “NAV”. The nav DIV will be the container for our navigation, the code looks like this.

<div id="container">

<div id="nav">
</div><!--NAV-->

</div><!--CONTAINER ENDS-->

Inside the “nav” DIV mock up a simple list. Start off with an unordered list (UL) with a class of “navigation”, inside the unordered list create your list (LI) elements. Each list (LI) element should be given its own class so that we can style each list (LI) object.

The markup looks like this.

<div id="container">

<div id="nav">

<ul class="navigation">
<li class="home"><a href="#" title="Home">Home</a></li>
<li class="services"><a href="#" title="Services">Services</a></li>
<li class="portfolio"><a href="#" title="Portfolio">Portfolio</a></li>
<li class="works"><a href="#" title="Works">Works</a></li>
<li class="contact"><a href="#" title="Contact">Contact</a></li>
</ul>

</div><!--NAV-->
</div><!--CONTAINER ENDS-->

That’s our markup pretty much finished, lets begin to slice our navigation.

Preparing Our Navigation Images

Believe it or not but the navigation is only made up of one image. We’ll use one big image of both the normal and hover state of the navigation then use CSS to change the background position, this technique is also known as “CSS Sprites“.

The cool thing about using CSS sprites is that the image is only loaded once and once its loaded your hovers will work perfectly without an mishaps. My image size is only a total of 80KB which is nothing by today’s standards. The image looks like this.

Inset Menu Coding Tutorial

Lets get started.

Open up your navigation PSD file in photoshop, select the rectangular marquee tool then make a selection around the whole navigation making sure everything is included in the selection.

Inset Menu Coding Tutorial

Once you’ve made the selection go to “image > crop”. After cropping the image you will notice how small the canvas area has now become, we need to increase the canvas height so that we can fit the same navigation on underneath the first one.

Find out how big your current canvas size is then times the height by 2. My canvas area is 179 pixels in height so if i multiply mine by 2, my new canvas size becomes 358 pixels. To increase the canvas area go to “image > canvas size”.

Inset Menu Coding Tutorial

You should now have something like this.

Inset Menu Coding Tutorial

Duplicating The Navigation

Before we duplicate the whole navigation remove the hover state effect from which ever button you applied it too (if any).

Inset Menu Coding Tutorial

Select all layers to do with your navigation then duplicate them, keep them highlighted then move the whole navigation down directly underneath its original, be sure not to leave a gap between the two. You should have something like this.

Inset Menu Coding Tutorial

The top navigation will be how it will look once loaded in the browser, the bottom navigation is what it will look like when you hover over it.

On the bottom navigation you need to add your hover state to every button. Be sure not to move any of the text or the orb, as the slightest movement will be picked up in the browser.

Heres my complete navigation with the hover states added.

Inset Menu Coding Tutorial

Now before we save our navigation we need to remove the background layer so the two navigation’s are on a transparent background. Once you’ve removed the background save the image as “navigation.GIF” inside the images folder.

You will also need the brushed metal background in which we used for our navigation, just save it as “bg.PNG” inside the images folder.

Bringing It All Together

Open your “styles.CSS” file in your code editor so we can begin to add our CSS styles. The first set of styles are for our document background and container, the code looks like this.

body {
background-color: #c3c3c3;
background-image: url(../images/bg.gif);
background-repeat: repeat;
background-position: center top;
}

#container {
margin: auto;
width: 793px;
}

For the body we simply add our background image and repeat it, setting the background position to center top will ensure our background repeats from the top center of our browser.

For our container we set our margins to auto, this will center our contain within our browser. We then set a fixed width of 793 pixels, the fixed width should be the same width as our navigation image.

Inset Menu Coding Tutorial

The next set of styles are for our navigation container, navigation un-ordered list and list items.

#nav {
float: left;
width: 793px;
height: 179px;
}

.navigation li {
display: block;
float: left;
}

.navigation li a {
display: block;
float: left;
height: 179px;
text-indent: -9999px;
}

The main styles you need to be aware of are the fixed width and heights and the text indent. The fixed width’s should be the same width as the navigation image, the fixed heights should also be the same height as the navigation image.

The text indent hides the text labels by shifting them off the screen. The next set of styles are for navigation list (LI) items, if you can remember each list (LI) item had its own class assigned to it.

li.home a {
width: 160px;
background-image: url(../images/navigation.png);
background-repeat: no-repeat;
background-position: left top;
}

li.services a {
width: 158px;
background-image: url(../images/navigation.png);
background-repeat: no-repeat;
background-position: -160px top;
}

li.portfolio a {
width: 158px;
background-image: url(../images/navigation.png);
background-repeat: no-repeat;
background-position: -318px top;
}

li.works a {
width: 158px;
background-image: url(../images/navigation.png);
background-repeat: no-repeat;
background-position: -476px top;
}

li.contact a {
width: 159px;
background-image: url(../images/navigation.png);
background-repeat: no-repeat;
background-position: -635px top;
}

The styles on each list (LI) class are pretty simple, we basically add our navigation image as a background but change the background position of each list (LI) item. We also set a fixed width which reflects the width of each button. You can determine the width of each button by measuring the width in photoshop.

Inset Menu Coding Tutorial

The last and final set of styles we need to add are for our list (LI) hovers, the code is pretty much the same as the last set of styles we just need to adjust the background position so that the bottom navigation shows up.

li.home a:hover {
background-image: url(../images/navigation.png);
background-repeat: no-repeat;
background-position: left bottom;
}

li.services a:hover {
background-image: url(../images/navigation.png);
background-repeat: no-repeat;
background-position: -160px bottom;
}

li.portfolio a:hover {
background-image: url(../images/navigation.png);
background-repeat: no-repeat;
background-position: -318px bottom;
}

li.works a:hover {
background-image: url(../images/navigation.png);
background-repeat: no-repeat;
background-position: -476px bottom;
}

li.contact a:hover {
background-image: url(../images/navigation.png);
background-repeat: no-repeat;
background-position: -635px bottom;
}

That’s it all done, you can test the navigation by clicking the button at the bottom, also look out for the FREE downloaded version soon.

Thanks for reading.

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

28 Responses to “Carbon Fibre Style Inset Navigation: The Code”

  1. aspire says:

    great tut rich as always, loving the new material and fresh tuts. keep em’ coming!

  2. Great Tut mate… WIll make some websites look very smart.

    G

  3. Awesome, thanks for the code.

  4. Hey Richard Carpenter great tuts as allways. Would be nice if you design an adult +18 template.

    Greetings and keep up the good work.

  5. Hawk-Tech says:

    Awesome code love the your tips great tricks man cheers

  6. nice tutorial, we got to learn lot of things from yo guys.

  7. Imon says:

    Thanks, the end result is wonderful

  8. DxDesigns says:

    I don’t like the actual navigation so much as the way you coded it to work. Thanks for posting :)

  9. D Poland says:

    wath i can say ?
    want more ^^

  10. Toki says:

    Thank You very much!!!

  11. Aafrin says:

    nice tutorial.
    thx 4 the code and detailed explanation

    i am not sure if any1 told u about this before.
    there is some problem loading images when getting the updates via rss feed
    i am using google reader. text loading fine only image.

  12. looks great, good job Rich!

  13. Adam B says:

    Can you incorporate a drop-down menu with image sprites – hover effects, like you did above? The reason why I asked that questions is because I am using this technique at my site but I need my services button to have a drop down menu, and their is nothing on the web saying you can do this… Could somebody confirm if you can do this for me and if so, I could use the help..

  14. Hello Richard Carpenter,

    I’ve seen all of your tutorials, are definetily great.

    Could you make a tutorial about making the 3 states of a button:
    1.- Normal
    2.- Mouse over
    3.- Mouse press

    Thanks for all and i hope soon you can make that tutorial please :)
    ( And if the tutorial is using JQuery effects (fade in, fade out) would be great )

  15. Oh, i forget 1 thing….

    If the button allows a drop down menu will be fantastic too :)

  16. Andrew says:

    Wish I could design like you… Its the only thing I’m struggling with now. I’ve been developing small websites for years.
    I don’t have much problems with coding as much as I do with designing. As they say, most developers are rubbish designers :)
    I really do like the way you just seem to come up with designs and colour schemes just like that.#
    May I request a small tutorial/tip in choosing a colour scheme? I seem to struggle with it a lot and I have yet to find a book nor tutorial that talks clearly about the subject.
    Closest I found that talks clearly about it is this http://www.worqx.com/color/index.htm
    but it just does not make sense as it does not explain the theories application.

  17. cool effects with detailed tutorial. good job

  18. vitmel says:

    Very nice tutorial. I am struggling with my nav bar. I wish I would know the proper way how to code hover buttons earlier. Now I am trying to fix all what I have done on my website. But it is kind of too late. I will definitely use this technique in my next projects.
    Thanks for your work.

  19. teamisuez says:

    Thankssss good job

  20. Martin says:

    Excellent tut mate.
    When will the free version also be available for download?

  21. Jim says:

    Richard, very nice toot. Can this be adjusted for width and height or does that require a complete start over.

  22. JayMarv says:

    Thanks Richard. This post inspired the navigation on my site http://simerabrandmedia.com. You’ve more than earned a spot on our credit page. Cheers.

  23. rex says:

    awesome… i admire u richard..

  24. ali says:

    Thanks alot for this tut, i’ve finally created my navbar, this has helped me alot, thanks champ!

  25. srinivas says:

    Thanks alot for this tut, i’ve finally created my navbar, this has helped me alot, thanks alot. Awesome… i admire u richard..

Leave a Reply