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

CSS How to Make a Website Adding Pages to a Website Add Iconography

Problem with the header when adding elements to the contact page

Good day,

I have created many pages and this is the first time I'm facing this.

When I created the contact.html page, I copied the code from index.html then delete the code inside <section>. I ran the code and everything is fine

However, whenever I add any element inside the section (such as <h3> or <p> the header goes down and a white space is showing up.

Note: I already included css header style to overcome this, it didn't work

Any help? Thanks

this is html code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title> FITEW | Home </title>
    <link rel="stylesheet" href="css/normalize.css">
    <link href='http://fonts.googleapis.com/css?family=Chewy|Salsa' rel='stylesheet' type='text/css'>
    <link rel=stylesheet href="css/main.css">
  </head>
  <body>
    <header>
      <a href="index.html" id="logo">
       <h1> 1,2,3 TEST</h1>
       <h2>Programmer</h2>
      </a>
      <nav>
        <ul>
          <li><a href="index.html"> Home </a> </li>
          <li><a href="previous_work.html"> Previous Work </a></li>
          <li><a href="About.html"> FITEW Profile </a></li>
          <li> <a href="contact_us.html" class="currentPage"> Contact us </a></li>
        </ul>
      </nav>
    </header>
    <div id="wrapper">
      <section>
        <h3> General information </h3>
        <p> To contact, bring ideas etc, please contact amal_abualrahi@yahoo.com </p>
      </section>
      <section>
        <h3> contact details</h3>
        <ul class="contact_info">
          <li class="phone"> </li>
          <li class="mail"> <a href="mailto:a@yahoo.com"> am@yahoo.com</a></li>
          <li class="twitter"> <a href="http://twitter.com/intent/tweet?screen_name=a"> @a</a></li>
        </ul>
      </section>
      <footer>
        <a href="http://twitter.com/a">
        <img src="img/twitter-wrap.png" alt="Twitter Logo" class="social_icon">
          </a>
        <img src="img/facebook-wrap.png" alt="Facebook Logo" class="social_icon">
        <p> &copy; 2014.</p>
      </footer>
        </div>
  </body>
</html>

this is the css code:

/*********************************
GENERAL
**********************************/
/* site body */
body
{
  background-color:#ffffff;
  color: #000000;
}

a
{
  text-decoration:none;
  color: #6ab46b;
}

nav a.currentPage
{
  color: #32673f;
}

#logo
{
  text-align:center;
  margin: 0;
}

header {
  background-color: #6ab46b;
  border-color: #599a68;
  float: left;
  margin: 0 0 30px 0;
  padding: 5px 0 0 0;
  width:100%;
}

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



h1, h2
{
  color: #ffffff;
  font-weight:normal;
  line-height: 0.8em;
}

nav
{
  background-color:#599a68;
  text-align:center;
  margin: 20px 0 0;
  padding:10px 0;
}

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

}

nav li
{
  display: inline-block;
}

nav a 
{
  font-weight:800;
  padding:15px 10px;
}
nav a, nav a:visited 
{
  color:#ffffff;
}

nav a:hover
{
  color: pink;
}
p
{
  font-family: 'Salsa', sans-serif;
  font-size: 1.75em;
}

img {
  max-width: 100%;
}

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

#gallery li {
  float: left;
  width: 45%;
  margin: 2.5%;
  background-color:#f5f5f5;
  color:#bdc3c7;
}

#gallery li a p {
  margin:0;
  padding: 5%;
  font-size:0.75em;
  color: #bdc3c7;
}

footer {
  clear:both;
}

.social_icon
{
  width:20px;
  height:20px;
  margin:0 5px;
}

.contact-info {
  list-style:none;
  padding: 0;
  margin:0;
  font-size:0.9em;
}

.contact-info li.mail a {
  background-image:url('../img/phone.png')
}

Hi,

Can you post your HTML/CSS relating to the issue or a link so we can see what is happening please?

Thanks

-Rich

Hi Amal,

I can't replicate this. Can you give me an example of the code you're trying to add and where you're adding it please?

Thanks

-Rich

4 Answers

Rich Bagley I have added them to the Question, thanks

Hi Rich Bagley

the code works fine when there is nothing in the page, or when I add only unordered lists inside the section element.

for example:

''' html

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> FITEW | Home </title> <link rel="stylesheet" href="../css/normalize.css"> <link href='http://fonts.googleapis.com/css?family=Chewy|Salsa' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="../css/main.css"> </head> <body> <header> <a href="index.html" id="headerLink"> <img src="../img/logo.png" alt="FITEW Logo" id="logo" height="100" width="390"> </a> <nav> <ul> <a href="index.html" class="currentPage"> <li> Home </li> </a> <a href="preWork.html"> <li> Products </li> </a> <a href="aboutUs.html"> <li> Meet FITEW </li> </a> <a href="contact.html"> <li> Contact us </li> </a> </ul> </nav> </header> <div id="wrapper"> <section> </section> </div> <footer> <a href="http://twitter.com/FITEW"> <img src="../img/twitter-wrap.png" alt="Twitter Logo" class="social_icons"> </a> <p> © Copy rights reserved to FITEW, 2014 </p> </footer> </body> </html>

'''

this code ok and the header shows up the page with no white space, but when I add a paragraph for example, the header is replaced and pushed down, and white space shows upper.

'''html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> FITEW | Home </title> <link rel="stylesheet" href="../css/normalize.css"> <link href='http://fonts.googleapis.com/css?family=Chewy|Salsa' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="../css/main.css"> </head> <body> <header> <a href="index.html" id="headerLink"> <img src="../img/logo.png" alt="FITEW Logo" id="logo" height="100" width="390"> </a> <nav> <ul> <a href="index.html" class="currentPage"> <li> Home </li> </a> <a href="preWork.html"> <li> Products </li> </a> <a href="aboutUs.html"> <li> Meet FITEW </li> </a> <a href="contact.html"> <li> Contact us </li> </a> </ul> </nav> </header> <div id="wrapper"> <section> <p> ONLY ADDING THIS WILL CAUSE THE HEADER TO BE SHIFTED DOWN </p> </section> </div> <footer> <a href="http://twitter.com/FITEW"> <img src="../img/twitter-wrap.png" alt="Twitter Logo" class="social_icons"> </a> <p> © Copy rights reserved to FITEW, 2014 </p> </footer> </body> </html>

'''

I really can not figure out why this is happening ! and how adding elements outside the header could effect the position of the header!

Thank you for your help, I appreciate it

You've got to set margin to the element, which you wanna use as first in "section". I got exactly the same problem, in section i had only "h3" and then only h3 {margin: 0 0 1em 0;} in css file fixed it.

P.S. - Sorry for any grammar mistake. I'm not native.

Hi Amal,

Really sorry for the delay, I had missed your posts for some reason.

As Lukáš has pointed out it could be due to the margin (or possibly padding) on the section / p tag. The easiest way to determine which is causing this would be to use the browser's developer tools. You will then be able to see the box model for the element you have selecting and identify whether it is the margin or the padding affecting this. You can also edit this directly in the browser before applying it to your style sheet for testing.

Hope that helps

-Rich