Aslet
Aslet

Reputation: 21

Why is this CSS navbar not completely at the top?

Here's the code of the navbar:

#nav {
    width: 100%;
    float: left;
    margin: 0 0 1em 0;
    padding: 0;
    background-color: #f2f2f2;
    border-bottom: 1px solid #ccc;  }
#nav ul {
    list-style: none;
    width: 800px;
    margin: 0 auto;
    padding: 0; }
#nav li {
    float: left; }
#nav li a {
    display: block;
    padding: 8px 15px;
    text-decoration: none;
    font-weight: bold;
    color: #069;
    border-right: 1px solid #ccc; }
#nav li:first-child a {
    border-left: 1px solid #ccc; }
#nav li a:hover {
    color: #c00;
    background-color: #fff; }

As requested, here's the HTML of the navbar:

<div id="nav">
    <ul>
        <li><a href="#">About Us</a></li>
        <li><a href="#">Our Products</a></li>
        <li><a href="#">FAQs</a></li>
        <li><a href="#">Contact</a></li>
        <li><a href="#">Login</a></li>
    </ul>
</div>

Shouldn't this make it be completely at the top since padding is zero? I'm new to webdesign... All help is greatly appreciated.

Upvotes: 0

Views: 2080

Answers (5)

skmasq
skmasq

Reputation: 4521

if this

body {
margin: 0;
}

isn't helping, then there is another css messing with these ones.

Here is example in jsFiddle

Upvotes: 0

Aslet
Aslet

Reputation: 21

I figured it out guys, thanks for your help though.

The problem was in this piece of code I hadn't posted:

div.content{
        border: 1px solid #fbfbfb;
        background-color: #fff;
        max-width: 640px;
        width: 100%;
        padding: 2%;
        margin: 0px  auto;
    }

I had the margin set to something else other than zero.

Upvotes: 0

Mr. Loop
Mr. Loop

Reputation: 187

Make sure you've done a reset at the top of your stylesheet to avoid browser defaults.

* {
margin:0;
padding:0;
}

there are likely other reset snippets you will find on the web, but this alone should help.

Upvotes: 4

G-Cyrillus
G-Cyrillus

Reputation: 106048

try a reset on body margin, else show us a test page:

body {margin:0;} 

Upvotes: 2

ponysmith
ponysmith

Reputation: 427

Make sure you're removing the margin and padding from the body and html tags:

html, body { margin: 0; padding: 0 }

Always a good idea to use a CSS reset if you're not already. It will take care of this for you.

Upvotes: 0

Related Questions