tags:

views:

69

answers:

4

I'm trying to create a page that has a header, subheader, leftnav, rightnav, main, and footer. But when I create the header and subheader, there is extra space that separates them. how do I get rid of it?

`/*the main parts of the script*/
body{
    background-color: #0080C0;
    font-family: Arial, Helvetica, Sans-serif;
    margin: 0px;
    padding: 0px;
    font-size: 15px;
}

#wrapper{
    width: 1000px;
    margin: 20px auto;
    background-color: white;
}

#header{
    background-color: aqua;
    padding-top: 2px;
    font-size: 15px;
    padding: 5px;    
}

#subheader{
    margin: 0px;
    background-color: fuchsia;
    height: auto;
}

#leftnav{
    float:left;
    width:200px;
    height:auto;
    background-color: green;
}

#rightnav{
    float:left;
    width: 200px;
    height: auto;
    background-color: red;
}

#main{
    float:left;
    width: 600px;
    height: auto;
    background-color: yellow;
    min-height: 500px;
}

#footer{
    clear:both;
    padding:15px;
    font-size: 12px;
    background-color: gray;
    text-align: center;
}`                                                                                                

//the HTML. very simple.                       
 <body>
<div id="wrapper">
    <div id="header">
    <?php $this->load->view("header"); ?>
    </div>

    <div id="subheader">
    <?php $this->load->view("subheader"); ?>
    </div>

    <span id="leftnav">
    <?php $this->load->view("leftnav"); ?>    
    </span>

    <span id="main">
    <?php $this->load->view($main); ?>    
    </span>

    <span id="rightnav">
    <?php $this->load->view("rightnav"); ?>
    </span>

    <div id="footer">
    <?php $this->load->view("footer"); ?>
    </div>

</div>
</body>  http://www.freeimagehosting.net/uploads/54aaee204f.jpg
+1  A: 

I ran your code and it doesn't look like there's extra space. Here are some things to try:

  • Make sure you're using a proper DOCTYPE
  • Make sure the PHP you're using isn't outputting extra whitespace
  • Use a modern browser (IE7+, FF3.6, Chrome 5, etc.)

The only other thing that could help us diagnose this better is to post the physical output of the PHP (view source, copy and paste).

Hope this helps!

mattbasta
Thanks for the input. I'm using the latest firefox, got no PHP scripts in yet. The div for main and footer doesn't have a margin separating them, but the header-subheader does? I posted the link for the image. http://www.freeimagehosting.net/uploads/54aaee204f.jpg
ggfan
You've definitely got PHP in there (the `<??>` tags), so that might be giving you hell. What it looks like to me is that you're inserting an element in your subheader that has a margin. Maybe a `<p>` tag? Again, double check that you've got a valid doctype (`<!DOCTYPE html>` will do) and toss some CSS in along the lines of `#subheader * {margin:0 !important;}`. You should notice a difference.
mattbasta
+1  A: 
#header{
    background-color: aqua;
    padding-top: 2px;
    font-size: 15px;
    padding: 5px;    
}

You have bottom padding on your #header, so this could look like 5px between your #header and #subheader which follows it. Although this should have an aqua background-color as it's strictly part of the #header.

w3d
+1  A: 

When I use this HTML code there is white space

  <body>
  <div id="header">
    header
  </div>
  <div id="subheader">
    sub
  </div>
<div id="wrapper">
  <div id="main">
    lorem ipsum dolor sit amet
  </div>
  <div id="rightnav">
    <ul>
      <li>ene</li>
      <li>due</li>
      <li>rabe</li>
    </ul>
  </div>
  <div id="leftnav">
    <ul>
      <li>ene</li>
      <li>due</li>
      <li>rabe</li>
    </ul>
  </div>
  <div id="footer">
    <ul>
      <li>ene</li>
      <li>due</li>
      <li>rabe</li>
    </ul>
  </div>
</div>

But when I put headers in wrapper there is no white space

<div id="wrapper">
  <div id="header">
    header
  </div>
  <div id="subheader">
    sub
  </div>
  <div id="main">
    lorem ipsum dolor sit amet
  </div>
  <div id="rightnav">
    <ul>
      <li>ene</li>
      <li>due</li>
      <li>rabe</li>
    </ul>
  </div>
  <div id="leftnav">
    <ul>
      <li>ene</li>
      <li>due</li>
      <li>rabe</li>
    </ul>
  </div>
  <div id="footer">
    <ul>
      <li>ene</li>
      <li>due</li>
      <li>rabe</li>
    </ul>
  </div>
</div>

Maybe that will help

jcubic
A: 

If you have a block elements (h1,h2... ul etc.) in your subheader you should reset their default margins to avoid this 'white space'. Fore example:

<style>
    #subheader ul { margin:0px; padding:0px;}
</style>
Vasil Dakov