Create a Customer Header with Links using CSS

CSS is a very powerful tool. Here we examine how to create a customer header with links, very much like the one seen at www.2spheres.co.uk.

First of all, decide if you want your header to have solid colour or a gradient of colour. If you decide to opt for the latter then you will need to open up Photoshop or you favourite graphics editor.

Creating a Gradient and Exporting It
We will make our header gradient in Photoshop first.

Create a new image, approx 100 pixels wide and 55 pixels high. Now, using the gradient colour picker in Photoshop (find this by selecting the gradient tool from the left hand tool bar and then selecting the drop down box on the top tool bar with a picture of a gradient on the front) choose 2 colours. My advice would be to choose 2 similar colours, for example, a dark red #9f0202 and an ever so slightly lighter red #c80404.

The Gradient Picker

Using the gradient tool, hold shift and draw a gradient on your art canvas, dragging from top to bottom. This will ensure your gradient is vertical.

This next step isn’t essential but it helps your website become more optimised when it loads. Go to Image > Image Size and untick the box which says ‘Constrain Proportions’. Now resize the image width to 1 pixel.

Now go to File > Save for Web and Devices. Save your 1 pixel wide image as a png-24 and call it something memorable like “headerbg”.

Adding Your Gradient To Your Web Site Using CSS
Here’s where we get down to some serious coding. Hand coders and Dreamweaver users will understand what to do.

Create your new HTML document and add a div. The code you will need for valid markup of your HTML doc with a div will 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″ />
</head>
<body>
<div id=”header”> </div>

Now we will enter our CSS. To keep it simple, add the CSS to the HTML document (rather than creating a separate file which is actually best practice but more complex). We will deal with creating separate CSS files at a later date.
The CSS must be placed in the head tag of the document. For Dreamweaver users, go to Window > CSS Styles to view the relevant dialog box. Your CSS will start to shape up like this:
<style type=”text/css”>
<!–
#header {
}
–>
</style>

#header is the name of the div we created earlier using HTML. You can call it whatever you like as long as the CSS and HTML name for the element match up.
Your div will automatically span from the left hand side to the right hand side of the page. The following code will set you div properties:
#header {
text-align: center;
height: 35px;
padding-top: 20px;
font-family: “Trebuchet MS”, Arial, Helvetica, sans-serif;
font-size: 0.7em;
font-weight: lighter;
letter-spacing: 0.2em;
background-image: url(images/headerbg.png);
background-repeat: repeat-x;
}

Our CSS is telling the browser a few things here;
- The text must be centred
- The height is 35px. Add the padding on and this makes 55px (the total height of our header background image)
- The font we want to use
- The font size
- The weight of the font
- The space between the letters we type
- The location of the image we just created in photoshop
- The direction we want it to span. x is left to right and y is up and down.
You should have something which looks like this:
What your work should look like

Our div spanning across the page with a gradient

With that complete, the final stage is to add some links. To do this, we will create a UL, or unordered list. There are some complex rules which need to be applied here to make this work so keep and eye on the code:

HTML CODE FOR THE UL IS LIKE THIS:

<div id=”header”>
<ul>
<li class=”first”><a href=”index.html”>HOME</a></li>
<li><a href=”link.html”>ABOUT</a></li>
<li><a href=”link.html”>GALLERY</a></li>
<li><a href=”link.html”>CONTACT</a></li>
</ul>
</div>

Notice that we have added a class of “first” to one of our list elements. This is very important for later on.

Next, we add the CSS in to our head to style the UL. You will need to create a new rules as follows:

#header ul li  {
border-left-width: 1px;
border-left-style: solid;
border-left-color: #F482B6;
list-style-type: none;
display: inline;
padding-top: 25px;
padding-bottom: 18px;
text-align: center;
padding-left: 20px;
padding-right: 12px;
margin: 0px;
}

And now, create another new rule to remove the first left aligned border from the links:

#header ul .first {
border: none;
}

To briefly run over what we have asked our code to do:
- We have specified a border on the left. This is used as a visual separator for our links.
- We have also specified border type and colour.
- We have told the browser that our UL is not a visual list and it needs to be displayed in a line.
- We have added padding to increase the hotspot area of each link and to give more space between the links.
- We have specified a zero margin

View Some Code
If you want to take a more in depth look at the code which we used to create this you can go to www.2spheres.co.uk. The header on this site is identical to what we have just created. The CSS and HTML in the tutorial is fully compliant and can be checked at W3C for official validation.

Tags: , , , , ,

2 Responses to “Create a Customer Header with Links using CSS”

  1. Alex (Admin) says:

    Hi Shan, Thanks for stopping by to read my Blog. If you want to contribute then please feel free to contact me at alex@2spheres.co.uk. If you have a web design related topic which you want to discuss then i’d be happy to let you contribute.

    Thanks =]

  2. Shan Juhas says:

    hey this blog is great. I’m glad I came by this blog. Maybe I can contribute in the near future. PM ME on Yahoo AmandaLovesYou702

Leave a Reply