GetDotted Domains

Viewing Thread:
"[CSS] HTML Lists + CSS = Navigation Menu"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Wed 07/10/09 at 14:45
Regular
"Devil in disguise"
Posts: 3,151
You can read about HTML lists in a previous tutorial. And you can also find some basic CSS techniques here. What I want to cover is one of the most popular ways to use lists and that is for your navigation. So a basic html list of links would looks like so...

<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">F.A.Q.</a></li>
<li><a href="#">Contact Us</a></li>
</ul>

And that looks like this.
Nothing special so far its just a list of links but you can at least see how it might end up as a navigation. So we start to style it with some css.

The first thing we want to do is get rid of the default styling thats already there. Those being the underlining of text on links and the padding & bullets elements on the list. To do this we'll define a CSS ID called nav and assign it to the list tag (<ul id="nav">)
And our CSS will be

#nav {
margin: 0;
padding: 0;
list-style-type: none;
}

#nav a {
text-decoration:none;
}

And that looks like this. Ok so it looks even less like a usable navigation at the moment.
Notice I'm using css selectors here. "#nav a" means apply this style to all a tags within the element I assign the ID #nav to.

Now we can do our first real bit of styling though. What I want to do is put some space between links, give them a background, a border and make the text white. To do that I'll use the css properties background-color, border and padding

My new CSS looks like

#nav {
margin: 0;
padding: 0;
list-style-type: none;
}

#nav a {
text-decoration:none;
padding:4px 10px;
background-color:#2175bc;
border:1px #000 solid;
color:#FFF;
}

And that looks like this. Thats a step in the right direction, kind of. :)

Theres a few things we need to correct though. The links are overlapping each other and they are various lengths. To fix the length, the obvious answer is to apply a width property to my list. This wont work on its own though. My link tags are in-line elements. This type of element uses as little space as possible (and thus effectively ignores my width assignment). To make this work though, I need my link tag to use all the space available to it and expand into the width I set on my list. So the solution is to turn my link into a block element. And I can use the display property to do that. Fortunately doing this is also going to fix the problem of my links overlapping as block elements wont overlap in this situation.
See the results for yourself.

Anyway, the CSS for that looks like


#nav {
margin: 0;
padding: 0;
list-style-type: none;
width:12em;
}

#nav a {
text-decoration:none;
padding:4px 10px;
background-color:#2175bc;
border:1px #000 solid;
color:#FFF;
display:block;
}

Finally it looks like a useable navigation. It doesnt look very good though.

My first problem is the border. As we're putting border around each element we're left with thick black lines in the middle. Each navigation item is an inside an
  • so I've got 2 sets of borders I can play with. Theres a bit of some room to be creative without using images at all.
    And my attempt at being "creative" can be seen
    here.

    What I've done is :
    Move the black border to the
  • Wed 07/10/09 at 14:54
    Moderator
    "Are you sure?"
    Posts: 5,000
    Nice post!










    If you hadn't skimped on the hosting of your demo site you could get a GAD for this!
    [s]Hmmm...[/s]
    Wed 07/10/09 at 14:45
    Regular
    "Devil in disguise"
    Posts: 3,151
    You can read about HTML lists in a previous tutorial. And you can also find some basic CSS techniques here. What I want to cover is one of the most popular ways to use lists and that is for your navigation. So a basic html list of links would looks like so...

    <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About Us</a></li>
    <li><a href="#">Services</a></li>
    <li><a href="#">F.A.Q.</a></li>
    <li><a href="#">Contact Us</a></li>
    </ul>

    And that looks like this.
    Nothing special so far its just a list of links but you can at least see how it might end up as a navigation. So we start to style it with some css.

    The first thing we want to do is get rid of the default styling thats already there. Those being the underlining of text on links and the padding & bullets elements on the list. To do this we'll define a CSS ID called nav and assign it to the list tag (<ul id="nav">)
    And our CSS will be

    #nav {
    margin: 0;
    padding: 0;
    list-style-type: none;
    }

    #nav a {
    text-decoration:none;
    }

    And that looks like this. Ok so it looks even less like a usable navigation at the moment.
    Notice I'm using css selectors here. "#nav a" means apply this style to all a tags within the element I assign the ID #nav to.

    Now we can do our first real bit of styling though. What I want to do is put some space between links, give them a background, a border and make the text white. To do that I'll use the css properties background-color, border and padding

    My new CSS looks like

    #nav {
    margin: 0;
    padding: 0;
    list-style-type: none;
    }

    #nav a {
    text-decoration:none;
    padding:4px 10px;
    background-color:#2175bc;
    border:1px #000 solid;
    color:#FFF;
    }

    And that looks like this. Thats a step in the right direction, kind of. :)

    Theres a few things we need to correct though. The links are overlapping each other and they are various lengths. To fix the length, the obvious answer is to apply a width property to my list. This wont work on its own though. My link tags are in-line elements. This type of element uses as little space as possible (and thus effectively ignores my width assignment). To make this work though, I need my link tag to use all the space available to it and expand into the width I set on my list. So the solution is to turn my link into a block element. And I can use the display property to do that. Fortunately doing this is also going to fix the problem of my links overlapping as block elements wont overlap in this situation.
    See the results for yourself.

    Anyway, the CSS for that looks like


    #nav {
    margin: 0;
    padding: 0;
    list-style-type: none;
    width:12em;
    }

    #nav a {
    text-decoration:none;
    padding:4px 10px;
    background-color:#2175bc;
    border:1px #000 solid;
    color:#FFF;
    display:block;
    }

    Finally it looks like a useable navigation. It doesnt look very good though.

    My first problem is the border. As we're putting border around each element we're left with thick black lines in the middle. Each navigation item is an inside an
  • so I've got 2 sets of borders I can play with. Theres a bit of some room to be creative without using images at all.
    And my attempt at being "creative" can be seen
    here.

    What I've done is :
    Move the black border to the
  • Freeola & GetDotted are rated 5 Stars

    Check out some of our customer reviews below:

    Impressive control panel
    I have to say that I'm impressed with the features available having logged on... Loads of info - excellent.
    Phil
    Excellent support service!
    I have always found the support staff to provide an excellent service on every occasion I've called.
    Ben

    View More Reviews

    Need some help? Give us a call on 01376 55 60 60

    Go to Support Centre

    It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.