2

I have a random gap appearing between div elements and I can't seem to make it go away. Problem is shown https://i.stack.imgur.com/ehy22.png

Here is my related code

 <div id="menuBar"><!--Hosts menu options-->
 </div>
 <!-- end #menuBar -->
 <div id="content">
 <p>hello</p>
 </div>

and CSS

#menuBar{
    width:900px;
    height:80px;
    margin: 0 auto;
    background:url(images/g2w2g.png) repeat-y;
}
#content{
    width:900px;
    margin: 0 auto;
    padding-top:0;
    background:url(images/g2w2g.png) repeat-y;
}

Thanks guys

Emil Condrea
  • 9,705
  • 7
  • 33
  • 52
Fonti
  • 1,169
  • 2
  • 9
  • 14

5 Answers5

4

When you use the p element to begin a new paragraph in HTML, it automatically creates some space above and below the content.

Add

p {
    margin:0px;
    padding:0px;
}

EXAMPLE

SaturnsEye
  • 6,297
  • 10
  • 46
  • 62
2

If you add bottom:16px; into #content div that will fix the gap with a position:relative;

ByronMcGrath
  • 365
  • 2
  • 3
  • 20
  • This works, but you would need to apply the same rule to each div that has `

    ` where as removing padding from `

    ` solves it on a whole

    – SaturnsEye Feb 20 '14 at 09:01
0

You can solve this adding display: inline-block; to your #content div.

Here's a Fiddle example for you

ManelPNavarro
  • 579
  • 7
  • 21
0

Check the margin on the paragraph or add some padding to the content div. That might fix it.

0

Its because your p tag still has the default margin and padding placed on it by the browser. You should do

p {
    padding:0px;
    margin:0px;
}

You should also consider using a CSS reset. Every browser has its own default 'user agent' styles. By including a reset it sets all of these default styles to null which should avoid any inconsistencies across different browsers. One important thing to remember is to include your css reset styles before any other styles. For example

<link rel="stylesheet" type="text/css" href="reset.css" /><!-- CSS reset in here -->
<link rel="stylesheet" type="text/css" href="style.css" /><!-- Your styles in here -->

I reccomend you take a look at these two links CSS Reset Normalize.css

Pattle
  • 5,983
  • 8
  • 33
  • 56