Skip navigation
Currently Being Moderated

Why do I have unwanted space between all my Divs?

Apr 25, 2012 1:29 PM

Tags: #div #dreamweaver #space #unwanted #divs #container

I'm a coding beginner- however, I can't for the life of me figure out why I have about 10 pixels above and below each of my divs. Can anybody help?

Here's my code-

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

<style type="text/css">

<!--

body {

          margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */

          padding: 0;

          text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */

          color: #000000;

          font-family: Verdana, Arial, Helvetica, sans-serif;

          font-size: 100%;

          background-color: #191919;

          background-image: url(../Images/repeat.jpg);

          background-repeat: repeat;

}

 

 

/* Tips for Elastic layouts

1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.

2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.

3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.

*/

.oneColElsCtrHdr #container {

          width: 100%; /* the auto margins (in conjunction with a width) center the page */

          border: 0px none #000000;

          text-align: left; /* this overrides the text-align: center on the body element. */

          margin-top: 0;

          margin-right: auto;

          margin-bottom: 0;

          margin-left: auto;

          background-color: #FFFFFF;

          background-image: url(../Images/repeat.jpg);

          background-repeat: repeat;

          color: #FFC;

}

.oneColElsCtrHdr #header {

          background: #DDDDDD;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */

          width: 100%;

          padding-top: 0;

          padding-right: 0px;

          padding-bottom: 0;

          padding-left: 0px;

}

.oneColElsCtrHdr #header h1 {

          margin: 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */

          background-attachment: scroll;

          background-image: url(../Images/headerwologo.jpg);

          background-repeat: repeat-x;

          width: 100%;

          padding-top: 0px;

          padding-right: 0;

          padding-bottom: 0px;

          padding-left: 0;

          height: 140px;

}

.oneColElsCtrHdr #mainimage {

          background-color: #FFFFFF;

          width: 100%;

          margin: 0px;

          padding: 0px;

}

 

 

.oneColElsCtrHdr #yellowbar {

          background-color: #FFFFFF;

          width: 100%;

          background-image: url(../Images/seperatebar.jpg);

          background-repeat: repeat-x;

          height: 15px;

}

 

 

.oneColElsCtrHdr # {

          background-color: #FFFFFF;

          width: 100%;

}

 

 

.oneColElsCtrHdr #mainContent {

          background-color: #FFFFFF;

          background-image: url(../Images/repeat.jpg);

          background-repeat: repeat;

          padding-top: 0;

          padding-right: 22px;

          padding-bottom: 0;

          padding-left: 22px;

}

.oneColElsCtrHdr #footer {

          padding: 0 0px; /* this padding matches the left alignment of the elements in the divs that appear above it. */

          background:#DDDDDD;

}

.oneColElsCtrHdr #footer p {

          margin: 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */

          background-image: url(../Images/footer.jpg);

          background-repeat: repeat-x;

          height: 140px;

          width: 100%;

          padding-top: 0px;

          padding-right: 0;

          padding-bottom: 0px;

          padding-left: 0;

}

-->

</style></head>

 

 

<body class="oneColElsCtrHdr">

<div id="container">

  <div id="header">

    <h1> </h1>

  <!-- end #header --></div>

  <div id="mainimaget">

    <h1><img src="../Images/mainillustrationbig.jpg" width="100%" height="auto" /></h1>

  <!-- end #mainContent --></div>

  <div id="yellowbar">

    <h1> </h1>

  <!-- end #mainContent --></div>

  <div id="mainContent">

    <h1> Main Content </h1>

    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at,  odio. Donec et ipsum et sapien vehicula nonummy. Suspendisse potenti. Fusce  varius urna id quam. Sed neque mi, varius eget, tincidunt nec, suscipit id,  libero. In eget purus. Vestibulum ut nisl. Donec eu mi sed turpis feugiat  feugiat. Integer turpis arcu, pellentesque eget, cursus et, fermentum ut,  sapien. Fusce metus mi, eleifend sollicitudin, molestie id, varius et, nibh.  Donec nec libero.</p>

    <h2>H2 level heading </h2>

    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.</p>

    <p> </p>

  <!-- end #mainContent --></div>

  <div id="footer">

    <p> </p>

  <!-- end #footer --></div>

<!-- end #container --></div>

</body>

</html>

 
Replies
  • Currently Being Moderated
    Apr 25, 2012 1:31 PM   in reply to KaileneD

    Can you upload the problem page to the web and post a link so we can troubleshoot it in our browsers?

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 25, 2012 11:34 PM   in reply to KaileneD

    A few things could be causing this.

     

    The content inside your divs are all <h1> tags which have a margin by default. Add h1{margin:0; padding:0;} to your CSS which makes all instances of <h1> have zero margin. I would remove he head tags surrounding the image as they are not required.

     

    Also, there is a typo in one of your Div tags. <div id="mainimaget"> should be <div id="mainimage">.

     

    The zero margins can also be added to your id rules in the CSS which should generally be standard practice as it prevents browsers adding their own spacing.

     

    Hope it helps.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points