2

When I use the margin-left it works. But the margin-top does not work. Anyone know why the on does work and the other doesn't?

Html code

<div id="footer"> <!-- BEGIN FOOTER -->
<p class="copyright"> Copyright © </p>
</div> <!-- END FOOTER -->

Css

#footer {

background-image: url(../website/images/footer.png);
width: 1200px;
height: 100px;

}

p.copyright {

margin-top: 10px;
margin-left: 120px;

}
user1548544
  • 2,875
  • 5
  • 19
  • 17
  • 1
    What is above your footer? something that has been floated? positioned? Possible that the floats havent been cleared? – Moin Zaman Jul 28 '12 at 13:00
  • Here it works fine: http://jsfiddle.net/qyUMC/. Can you give more code – Idrizi.A Jul 28 '12 at 13:00
  • @Enve It doesn't work: http://jsfiddle.net/nFJgV/ – JJJ Jul 28 '12 at 13:02
  • your p tag default having margins, instead use margin-top:20 or something else for the top may be it will work – Jack Jul 28 '12 at 13:13
  • @Enve's Example works, actually his own markup works perfectly, unless and untill he means that even the parent div is shifted below – Mr. Alien Jul 28 '12 at 13:15
  • @Mr.Alien It's a fair bet that he wants the margin to apply inside the div. Otherwise he wouldn't have asked the question. – JJJ Jul 28 '12 at 13:22

3 Answers3

2

It's called margin collapse. It happens when one block element is the child of another block element. here are a couple of methods to tackle the problem.

1- Add a border to the element

2- Add 1px of padding

3- change the position property. Margins of absolutely and relatively positioned boxes don’t collapse.

I've recently written a blog post about that to learn more refer here

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
Faraz Kelhini
  • 3,925
  • 32
  • 38
0

try out this

#footer {
    background-image: url(../website/images/footer.png);
    width: 1200px;
    height: 100px;
    position:absolute;
}

p.copyright {
    background-color:red;
    margin-top: 10px;
    margin-left: 120px;
}​
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
Uttara
  • 2,496
  • 3
  • 24
  • 35
0

Try this:-

  #footer {
    background-image: url(../website/images/footer.png);
    width: 1200px;
    height: 100px;
    overflow:hidden; // add overflow
  }
    
  p.copyright {
    margin-top: 10px;
    margin-left: 120px;
  }
Community
  • 1
  • 1
SaurabhLP
  • 3,619
  • 9
  • 40
  • 70