1

I am getting an extra space both below and above my footer on my page, I have tried using margin:0; and padding also but it's still there.

here's my whole html code:

<div id="header">
    <div id="images">
        <img src="f1.png" />
        <img src="linkedin.png" />
        <img src="t1.png" />
        <div id="menu">
            <img src="email1.png" />
            <img src="pen_marker.png" />
        </div>
    </div>
</div>
<div id="main">
    <img src="url.jpg" />
</div>
<div id="footer"></div>

and here's my css part:

you can see the spaces in the image

body {
    margin:0;
}
#header {
    padding:0;
    margin:0;
    width:100%;
    background-color: rgba(0, 0, 0, .7);
    box-shadow: 0 0 4px 0 rgba(0, 0, 0, .7);
    -moz-box-shadow:0 2px 3px 0px rgba(0, 0, 0, .7);
    -webkit-box-shadow:0 2px 3px 0px rgba(0, 0, 0, .7);
    position: fixed;
}
#menu {
    margin-top: 5px;
    margin-right: 50%;
    float:right;
}
#menu img {
    padding-left:0;
}
#images img {
    margin-left:30px;
}
#main {
    width:100%;
    margin:0;
    padding:0;
}
#main img {
    width:100%;
}
#footer {
    height:60px;
    background-color: #000;
    margin:0;
    padding:0;
}

http://jsfiddle.net/NrxL4/

i am not able to figure out whether its because of inheritance or what.

EDIT:

There is still space below the footer:

enter image description here

showdev
  • 28,454
  • 37
  • 55
  • 73
Rahul Khatri
  • 287
  • 1
  • 4
  • 14

6 Answers6

2

I see what you mean.

By default, images are inline elements.
If you set that image to display:block, the space goes away.

#main img {
    width:100%;
    display:block;
}

Try it below:

body {
  margin: 0;
}

#header {
  padding: 0;
  margin: 0;
  width: 100%;
  background-color: rgba(0, 0, 0, .7);
  box-shadow: 0 0 4px 0 rgba(0, 0, 0, .7);
  -moz-box-shadow: 0 2px 3px 0px rgba(0, 0, 0, .7);
  -webkit-box-shadow: 0 2px 3px 0px rgba(0, 0, 0, .7);
  position: fixed;
}

#menu {
  margin-top: 5px;
  margin-right: 50%;
  float: right;
}

#menu img {
  padding-left: 0;
}

#images img {
  margin-left: 30px;
}

#main {
  width: 100%;
  margin: 0;
  padding: 0;
}

#main img {
  width: 100%;
  display: block;
}

#footer {
  height: 60px;
  background-color: #00F;
  margin: 0;
  padding: 0;
}
<div id="header">
  <div id="images">
    <img src="f1.png" />
    <img src="linkedin.png" />
    <img src="t1.png" />
    <div id="menu">
      <img src="email1.png" />
      <img src="pen_marker.png" />
    </div>
  </div>
</div>
<div id="main">
  <img src="http://www.fundraising123.org/files/u16/bigstock-Test-word-on-white-keyboard-27134336.jpg" />
</div>
<div id="footer"></div>

View on JSFiddle

Here is a screen-shot:

enter image description here

showdev
  • 28,454
  • 37
  • 55
  • 73
0

Try this

#main img {
width:100%;
display:block;
}
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
0

SEE this fiddle i have edited this might solve your problem

<div id="footer"></div>

http://jsfiddle.net/NrxL4/2/

0

About the space after footer, I have one question. Are the scroll bars visible? Since I don't see any in the first screenshot. May be the page is not long enough to fit your screen size. Try adding some more content before footer and check if the spacing persists.

Regards

EDIT:

To stick the footer to the bottom use the following code-

footer {
    position:absolute;
    margin:0;
    padding:0;
    bottom:0;
    left:0;
    width:100%;
    /* Include other footer properties */
}

I hope that helps :)

  • hmm i think its true, i dont needed any scroll bar – Rahul Khatri Oct 10 '13 at 11:38
  • If you want the footer to simply stick to the bottom without getting the scrollbars, you can give the footer absolute positioning and set the bottom and left properties to zero. Also set the width to 100% so the footer expands to full width of the view port. see the edit above – Arshad Ansari Oct 10 '13 at 16:26
0

This fixed mine:

body {
margin:0;
padding:0;
width:100%;
}

footer {
display:flex; /* could be block as well */
position:relative;
}
nancyeh
  • 1
  • 1
-2

auto position for fixed is top:8; and left:8;. so add

top: 0;
left: 0;

to your #header css.

see this question.

Community
  • 1
  • 1
Math chiller
  • 4,123
  • 6
  • 28
  • 44