user1555957
user1555957

Reputation: 33

Body element not sitting at top of page

trying to get my first HTML/CSS uni assignment sorted but have become a bit stuck on this. My body tag doesn't sit at the top of the page. I can ensure it does by giving it a negative margin, but I shouldn't need to do that, right? Any help would be much appreciated, thanks.

<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 strict//EN" "http://www.w3.org/TR/xhtml/DTD/xhtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PhotArt</title>
<link href="main.css" type="text/css" rel="stylesheet" />
</head>
<body>
<!--begin container -->
<div id="navigationContainer">  

<!-- begin navigation bar -->
     <div id="navigationBar">       
        <ul>
            <li><a class="logo" href="index.html">PhotArt</a></li>
            <li><a class="active" href="index.html">Home</a></li>
            <li><a href="#">Create your art</a></li>
            <li><a href="#">Framing</a></li>
            <li><a href="#">Originals</a></li>
            <li><a href="#">About us</a></li>
            <li><a href="#">Contact us</a></li>
        </ul>

There are a few other paragraphs after this but I doubt the html is causing any issues.

And then the CSS looks like this:

html {
    margin: 0;
    padding: 0;
}

body {
    margin: 0;
    padding: 0;
    border: 0;
}

#navigationContainer {
    background-color: #2f2f38;
    padding: 0;
    margin: 0 auto;
}

#navigationBar {
    padding: 0em 0em 10em 0em;
    background-color: #2f2f38;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

#navigationBar ul {
    margin-left: auto;
    margin-right: auto;
    width: 900px;
    padding: none;
}

#navigationBar li {
    list-style-type: none;
    display: inline;
    font: 1em "Trebuchet MS", Helvetica, sans-serif;
}

#navigationBar .active {
    color: #ffffff;
}

#navigationBar .logo {
    font: 3.5em "Trebuchet MS", Helvetica, sans-serif;
    color: #fcfcfc;
}

#navigationBar li a {
    text-decoration: none;
    color: #a6a4a4;
    margin-right: 30px;
}

#navigationBar li a:hover,
#navigationBar li a:active {
    color: #ffffff;
}

Upvotes: 3

Views: 9477

Answers (2)

JClaspill
JClaspill

Reputation: 1745

Try adding margin-top:0px; to #navigationBar

I also assume you've closed all your divs/tags in code below what you've given us.

Upvotes: 1

Mike S.
Mike S.

Reputation: 4879

You need to edit your CSS and add margin-top: 0px; to navigation bar:

#navigationBar ul {
margin-top: 0px;
margin-left: auto;
margin-right: auto;
width: 900px;
padding: none;
}

Upvotes: 2

Related Questions