Subscribe Via RSS

3174 Subscribers

Subscribe Via RSS
Subscribe Via Twitter

Followers

Subscribe Via Twitter
Simple CSS Menu

September 9th, 2008 in Coding Tutorials by Richard Carpenter

Simple CSS Menu

1 Star2 Stars3 Stars4 Stars5 Stars40 Votes, Rating: 4.75
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 322 posts.


Firstly lets create our simple navigation in photoshop, select the rectangular marquee tool and create your navigation, make it about 600 x 50 pixels you can create a fixed size rectangle by changing the style setting at the top of the screen.

Fill your rectangle with any color than add these layer styles to it.

Yout navigation should look like this.

Now using the text tool add your navigation text, of course we will be adding the text to our navigation in html, this is just so we no it looks ok.

Now on our navigation id like to add some sort of a rollover, so select the rectangular marquee tool and create a box under your text layer, im using the color #e1e1e1.

The rollover aint finished yet :) now add to triangle top and bottom of the navigation.

Thats it for the designing part, we will now code it in css to use for a website. You might want to save your PSD file at this point incase you need to use it again. After you have saved it hide your text layer, then goto “layer > merge visable”. Believe it or not we only need two images to create this navigation in css. Zoom in pretty close with the magnify tool then select the rectangular marquee tool and create a selection like this.

The dimensions for the selection are 1pixel wide and 50 pixel’s in height and the selection starts right at the top of the stroke and ends just as your drop shadow disapears. Create a new folder on your desktop called naviagtion, open your folder then create another new folder called “images”. Head back over to photoshop then press “ctrl + c” to copy your selection, then goto “file > new” press ok, your dimentions of selection should automatically be entered into the new dialog box. Just goto “edit > paste”. Now goto “file > save for web & devices” or if your using cs2 it will say “save for the web”. Navigate over to your folder and save it as “silver_nav_background.gif”.

Thats our first image, now lets create our 2nd image create a new document 200×50 pixels. Re-create your mouse over look.

Once you have re-created it goto “file > save for web & devices” or if your using cs2 it will say “save for the web”. Navigate over to your folder and save it as “silver_nav_mouseover.gif”.

Thats all we need to do in photoshop, head over to your naviagtion folder, backout of the images folder then open up notepad. Once it opens just goto “file > save as” and save it as style.css (DONT FORGET TO ADD THE .CSS part in the filename). Open up dreamweaver and create a new HTML document, also got “file > open” and open the style to css text file your prevously created. You should have to two pages open now in dreamweaver, you can switch between the two pages by clicking these two buttons.

Click your HTML page and click “code” to see the code view of that document. You’l be presented with this 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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>

We can leave all that just change the title where it says “Untitled Document”, Change to what ever you want il call mine navigation tutorial. Inbetween the “BODY” tags mark out your naviagtion to do this we add our starting DIV tags and create our text and links.

	<div class="silver">
	<div id="nav">
	<ul>
	<li><a href="http://www.hv-designs.co.uk" title="Home" class="current">Home</a></li>
	<li><a href="http://www.hv-designs.co.uk" title="Button 2">Button 2</a></li>
	<li><a href="http://www.hv-designs.co.uk" title="Button 3">Button 3</a></li>
	<li><a href="http://www.hv-designs.co.uk" title="Button 4">Button 4</a></li>
	<li><a href="http://www.hv-designs.co.uk" title="Button 5">Button 5</a></li>
	</ul>
	</div>
	</div>

You will notice in the HTML code above in the 1st link there is a “class=current” this means when you change pages the rollover will stay active for that specific page. You will have to add the class to each link on there own pages. We have also got to add some css in the style sheet for it to work.

You webpage should look like this in dreamweaver at this stage.

Thats all we need for the naviagtion, we just need to add one more bit of code. Inbetween the “HEAD” tags add this little bit of code.

<link rel="stylesheet" href="style.css" type="text/css" />

This snippet of code attches our style sheet to the HTML document. You HTML document should now look like this.

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Navigation Tutorial | HV-Designs.co.uk</title>
</head>

<body>

	<div class="silver">
	<div id="nav">
	<ul>
	<li><a href="http://www.hv-designs.co.uk" title="Home" class="current">Home</a></li>
	<li><a href="http://www.hv-designs.co.uk" title="Button 2">Button 2</a></li>
	<li><a href="http://www.hv-designs.co.uk" title="Button 3">Button 3</a></li>
	<li><a href="http://www.hv-designs.co.uk" title="Button 4">Button 4</a></li>
	<li><a href="http://www.hv-designs.co.uk" title="Button 5">Button 5</a></li>
	</ul>
	</div>
	</div>

</body>
</html>

Save your HTML file as index.html in your naviagtion folder on your desktop. Now open your CSS file and add this at the very top of your file.

body {
margin-left: 0px;
margin-top: 20px;
margin-right: 0px;
margin-bottom: 0px;
}

This bit of css sets the margins around the page also known as the “BODY”, we want our navigation to go right to the end of our browser so it looks nice and neat, the only margin we need is the top margin which is set at 20pixels. Now add this underneath your body item.

/* ---------------------- silver nav ---------------------- */
.silver #nav{
position:relative;
display:block;
height:50px;
font-size:11px;
font-weight:normal;
background:transparent url(images/silver_nav_background.gif) repeat-x top left;
font-family:Arial,Verdana,Helvitica,sans-serif;
text-transform:uppercase;
}

The code above means.

position:relative = The position property places an element in a static, relative, absolute or fixed position.
display:block = The element will be displayed as a block-level element, with a line break before and after the element.
height:50px = Height of the navigation, this needs to be changed if your navigation images arn’t 50 pixels high.
font-size:11px = Sets the size of the text to 11pixels.
font-weight:normal = bold or not.
background:transparent url(images/silver_nav_background.gif) repeat-x top left = This part is IMPORTANT as it sets our navigation background image in our case the image we created within photoshop.
font-family:Arial,Verdana,Helvitica,sans-serif = Fonts to use.
text-transform:uppercase = Text is all in capitals.

Your navigation should now look like this.

Now add,

.silver #nav ul{
margin:0px;
padding:0;
list-style-type:none;
width:auto;
}

The code above means.

margin:0px = Margin around the unordered list.
padding:0 = Padding around the unordered list.
list-style-type:none = The listStyle property sets all list properties in one declaration.
width:auto = Wdith of the unordered list is set to auto so the its centered no matter what size the browser window is.

Now add,

.silver #nav ul li{
display:block;
float:left;
margin:0 1px 0 0;
}
.silver #nav ul li a{
display:block;
float:left;
color:#3A3A3A;
text-decoration:none;
padding:14px 22px 0 22px;
height:28px;
}

A breakdown of the above styles listed below.

display:block = The element will be displayed as a block-level element, with a line break before and after the element.
float:left = The float property sets where an image or a text will appear in another element.
color:#3A3A3A = The color of our text in a normal state.

And finally add,

.silver #nav ul li a:hover,.silver #nav ul li a.current{
color:#333333;
background:transparent url(images/silver_nav_mouseover.gif) no-repeat top center;
}
/* ---------------------- END silver nav ---------------------- */

This is where we set our mouseover image and activate the “current” class that i was talking about at the start of the tutorial. If you save your style sheet and open your HTML file you should have something like this *(CHECK LINK BELOW)*

VIEW FINISHED MENU.

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

41 Responses to “Simple CSS Menu”

  1. Colin says:

    Very nice tutorial, Good outcome :D

  2. Victor says:

    great tutorial :)

  3. Dule says:

    Very nice! I was waiting for a CSS tutorial for so long. Maybe you could do more CSS tutorials in the future.
    Thanks!!!

  4. ADMIN says:

    thanks for the comments, i have some css tutorials lined up. Just takes so much time writing them up.

    Many Thanks

  5. Palomino says:

    Thanks!!!

  6. Elliot says:

    I love tuts like this.
    Admin you need to run automatic cron jobs, or add a script that will email the subscribers right when you post.
    This came about a day late. Maybe you have a lot of people and it might take some time.
    I hope that you don’t manually have to fun the script through a file.

  7. Elliot says:

    ^You should make your own subscriber, its not really hard:
    <?php
    if(isset($_POST['subscribe']){
    $email=$_POST['email'];
    $emailquery=mysql_query(“INSERT INTO subscribers (email) VALUES(‘$email’)”)or die(“error occurred, please try again later”);
    if(mysql_affected_rows($emailquery)){
    echo”Thank you for subscribing!“; } }
    ?>
    Then inside your wordpress file, open the file in which you use to post your news:
    You will see something in the html()
    then add to the php:

    Just a rough draft of what it might look like.

  8. ADMIN says:

    e-mail subscriptions are done throu feedburner, there always late :(

  9. Elliot says:

    which is probably why you should make your own website.
    No doubt your really good at photoshop and css, which i am very weak at.
    But you can’t do much with just html, you need php&mysql.

  10. ADMIN says:

    i have made my own website lol

  11. Made my own site too lol

  12. Elliot says:

    I did the programming for mine, but i suck at this layout stuff lol.
    But thanks to you, im getting better :D!

  13. dor says:

    hey man!!
    thsi is a very good tutorial
    immma do it once i get my dreamweaver

  14. Anne says:

    Very nice ! Thank you very much for all your tutorials. CSS tutorials are very interesting.

  15. Avangelist says:

    Hey man, that is a nice simple bit of work.

    I have a question though.

    “display:block = The element will be displayed as a block-level element, with a line break before and after the element.”

    I thought display:block was used to remove this effect from inline objects not add it?

    Could you PM me with an update?

    cheers

  16. ADMIN says:

    i checked W3schools when writing the tutorial.

    “display:block = The element will be displayed as a block-level element, with a line break before and after the element.” is correct

  17. Nice looking nav and easy to follow tutorial – thanks

  18. Hernan says:

    Excelent tutorial, i learned a lot, that is because i know nothing about css or html. But i have one question.
    How do you center (align) the menu on a web page?

    Thanks

  19. Nervy says:

    Hi, i have a problem with the navigational bar, i want to add an image directly below the navigational bar but there is always a row of white space in between the bar and my image . Do u think you can help ?

  20. Razor says:

    How would you center the nevigation menu so that the buttons are in the middle?

  21. iCutty says:

    Very good tutorial. Very explanatory as well as great outcome. Thank you!

  22. Dudewtf says:

    this is the best photoshop tutorial site ever

  23. Nervy says:

    Hi, great tutorial, but i got a question, when i added more link to the menu and when i decrease the size of my browser(to let say 60% width), the extra link just jutted out of the sliver back ground. How do i solve that ? T_T

  24. HUREBOCK says:

    really great tut! easy and beautiful menu! thanks.

  25. Ale says:

    Thanks a bunch, man!

  26. To align a menu, or to align anything in the center you add theese properties in the wrapper of your site:

    margin-left:auto;
    margin-right:auto;

  27. really cool one, both Photoshop and css in one tutorial. thanks

  28. Seth says:

    I have a question….. I have coded the HTML and CSS i think correctly, and saved them, but when i go to view in Safari its just a list of links and i tried Live View and Design in Dreamweaver…

    and if i delete the
    (1..silver #nav ul li a:hover,.silver #nav ul li a.current{
    2.color:#333333;
    3.background:transparent url(images/silver_nav_mouseover.gif) no-repeat top center;
    4.}
    5./* ———————- END silver nav ———————- */)

    Then it shows the links in the nav bar but the hover doesnt work..
    Please help…

  29. Jitendra says:

    dear friend,

    i am not able to get the background images, i have checked and followed all the steps properly.

    (silver_nav_background.gif) step does not appear.

    Thanks for the help in advance.

  30. seo says:

    good .thanks

  31. Saad says:

    OKAY, this is very useful and i really like it, i am just trying to figure out few things like…….

    .silver #nav ul{
    margin:0px;
    padding:0;
    list-style-type:none;
    width:auto;
    }

    .silver #nav ul li{
    display:block;
    float:left;
    margin:0 1px 0 0;
    }

    .silver #nav ul li a{
    display:block;
    float:left;
    color:#3A3A3A;
    text-decoration:none;
    padding:14px 22px 0 22px;
    height:28px;
    }

    .silver #nav ul li a:hover,.silver #nav ul li a.current{
    color:#333333;
    background:transparent url(images/silver_nav_mouseover.gif) no-repeat top center;
    }

    Why we are using “ul”, “ul li”, “ul li a”, “ul li a:hover,.silver #nav ul li a.current”

    When we have entered “.silver #nav” in the beginning, would you please be more specific in explaining this process as you did in other breakdowns?

    Thanking you

  32. Good guide.
    Thanks!

  33. human7 says:

    Nice !

  34. Thomas Buza says:

    Just excellent, you are very talented. I am currently working on a site for a client and all of your work has really been a great inspiration. Thank you and good luck with everything.

  35. Lewis says:

    This is a great tutorial, thanks for this.

    I know what I’m doing when it comes to designing, but I suck at coding, and absolutely hate WYSIWYG editors like Webplus etc, so this is really helpful.

    One question, how would I have the links centred, instead of to the left like this?

    Thanks

  36. Thanks for the tutorial! I am trying to master CSS and this definitely helps me understand what I can accomplish with it :)

  37. Joey says:

    Admin.
    Thank you so much.
    You created awesome tutorials and psd files free for newbie for me.
    Thanks.

  38. Daniel says:

    GREAT!!!!! thanks

  39. Daniel says:

    Could you put a download link plz . . . im new in this, and will be more understandable if i see the files.. thanks anyways.

Leave a Reply