Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML How to Make a Website Adding Pages to a Website Add a New Page

Dan Dyson
Dan Dyson
1,788 Points

index.html top margin issue

Hi everyone,

on my index.html page, it seems there is a gap between the top of the page and the header bar.

What a I missing here?

I tried to put the body padding and margin to 0 but it still remains the same.

Can anyone suggest a solution?

Here is the content of my index.html file:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Dan Dyson | Drummer | Web Developer</title> <link rel="stylesheet" href="CSS/normalize.css"> <link href='https://fonts.googleapis.com/css?family=Changa+One|Open+Sans:400,400italic,700,700italic,800' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="CSS/main.css">

</head> <body> <header> <a href="index.html" id="logo"> <h1>Dan Dyson</h1> <h2>Drummer | Developer</h2> </a> <nav> <ul> <li><a href="index.html" class="selected">Portfolio</a></li> <li><a href="about.html">About</a></li> <li><a href="contact.html">Contact</a></li> </ul> </nav> </header> <div id="wrapper"> <section id="gallery"> <ul> <li>

        <a href="Img/numbers-01.jpg">
          <img src="Img/numbers-01.jpg" alt=""/> 
        </a>
          <p>Expermentation with colour and texture.</p>


      </li>

      <li>

        <a href="Img/numbers-02.jpg">
          <img src="Img/numbers-02.jpg" alt=""/> 
        </a>
          <p>Experimentation with texture and stuff</p>


      </li>

      <li>

        <a href="Img/numbers-06.jpg">
          <img src="Img/numbers-06.jpg" alt=""/> 
        </a>
          <p>Experimentation with texture and stuff</p>


      </li>

      <li>

        <a href="Img/numbers-09.jpg">
          <img src="Img/numbers-09.jpg" alt=""/> 
        </a>
          <p>Experimentation with texture and stuff</p>


      </li>

      <li>

        <a href="Img/numbers-01.jpg">
          <img src="Img/numbers-01.jpg" alt=""/> 
        </a>
          <p>Experimentation with texture and stuff</p>


      </li>


    </ul>  
  </section>
  <footer>
    <a href="http://twitter.cpom/detonatordd"><img src="Img/twitter-wrap.png" alt="Twitter Logo" class="social-icon"></a>
    <a href="https://www.facebook.com/dan.dyson.75"><img src="Img/facebook-wrap.png" alt="Facebook Logo" class="social-icon"></a>
    <p>&copy; 2016 Dan Dyson</p>
  </footer>

</div> </body>

</html>

and here is the content of my main.css file:

/********************* GENERAL *********************/

body { font-family: 'Open Sans', sans-serif; }

wrapper {

max-width: 940px; margin: 0 auto; padding: 0 5%; }

a { text-decoration: none; }

img { max-width: 100%; }

/********************* HEADING *********************/

header { float: left; margin: 0 0 30px 0; padding: 5px 0 0 0; width: 100%; }

logo {

text-align: center; margin: 0; }

h1 { font-family: 'Changa One', sans-serif; margin: 15px 0; font-size: 1.75em; font-weight: normal; line-height: 0.8em; }

h2 { font-size: 0.75em; margin: -5px 0 0; font-weight: normal; }

/********************* NAVIGATION *********************/

nav { text-align: center; padding: 10px 0; margin: 20px 0 0; }

nav ul { list-style: none; margin: 0 10px; padding: 0; }

nav li { display: inline-block; }

nav a { font-weight: 800; padding: 15px 10px; }

/********************* FOOTER *********************/

footer { font-size: 0.75em; text-align: center; clear: both; padding-top: 50px; color: #ccc; }

.social-icon { width: 20px; height: 20px; margin: 0 5px; } /********************* PAGE: PORTFOLIO *********************/

gallery {

margin: 0; padding: 0;

}

gallery li {

float: left; width: 45%; margin: 2.5%; background-color: #f5f5f5; color: #bdc3c7; list-style: none; }

gallery li a p {

margin: 0; padding: 5%; font-size: 0.75em; color: #bdc3c7; }

/********************* COLORS *********************/

/* site body */

body { background-color: #fff; color: #999; }

/* green header */ header { background: #000099; border-color: #000000; }

/* nav background on mobile */ nav { background: #0066ff; }

/* logo text */ h1, h2 { color: #fff; }

/*************** LINKS ***************/

/* nav link */ nav a, nav a:visited { color: #fff; }

/* selected nav link */ nav a.selected, nav a:hover { color: #000000; }

Thanks =)

7 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Do me a small favor and check to make sure that your css directory in your workspaces is named CSS. Yes, capitalization matters. When I look at the video and launch the workspace it pulls up a directory with css in lowercase. But here, you've linked to files in CSS in uppercase. I'm not convinced that any of your styles are being applied at all.

anil rahman
anil rahman
7,786 Points

Also the gap at the page can come from the:

<h1>Dan Dyson</h1>

The h1 tag has margin/padding that can make the gap appear.

Chris Roberts
Chris Roberts
3,970 Points

Strange, I used your code and changed the body's margin to 0 and that seemed to do the trick, perhaps a spelling error?

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I think the CSS isn't loading because he links to the folder CSS/ but the folder in workspaces is css. Note the capitalization.

Dan Dyson
Dan Dyson
1,788 Points

Thanks for your input guys!

Thanks for the heads up on that Jennifer; I've changed the capitalization on the css file itself and the links.

Unfortunately it still looks the same.

under GENERAL, my body css now says:

body { font-family: 'Open Sans', sans-serif; margin: 0; }

But the gap still appears

and Anil, I tried putting the h1's padding to 0 and the margin to 0 but its still the same?

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Open up the workspace and in the top right corner you'll see something that looks like a camera. Take a snapshot of your workspace and link it here so that we can see the whole thing in one go.

anil rahman
anil rahman
7,786 Points

Add these to your body css and it will work:

padding: 0;
  margin-top: -20px;
Dan Dyson
Dan Dyson
1,788 Points

Ah great that's done the trick, thanks Anil! :)