October 12, 201016 yr Hi, I'm starting a page with a #container div with static background image and 100% width, then within that I have a #main div at 960 px width and centered (using 0 auto margins). When I try to add a top margin to the #main div of 60px it puts a 60px white margin at the top of the whole page (so the background image of the container div starts 50px below the top of the screen). I just want the main div to have a top margin, not the container. I can put a header div in with the same background as the main static bg image but it is not aligned and i'm sure using margins would be a cleaner way to do it. Any ideas? Thanks
October 12, 201016 yr It sounds like margin collapse (Google it for an explanation) but basically you may achieve the result using padding-top: 60px; in the #main style instead of margin-top. A background for #main (if you have one) will show in the padding. If that doesn't do what you want, study margin collapse tutorials like http://www.howtocreate.co.uk/tutorials/css/margincollapsing Margin collapse may seem the wrong wording when you are getting an extra margin, but what may be happening is that the margin-top for the child #main div is extending outside its box (collapsing the box) and applying itself to the parent #container
October 14, 201016 yr Hey mate I encountered an issue like this before. Try adding padding-top: 1px; to the containing div. This usually fixes the issue but without seeing your code it's hard to be 100% sure of a solution. Jebediah Hi, I'm starting a page with a #container div with static background image and 100% width, then within that I have a #main div at 960 px width and centered (using 0 auto margins). When I try to add a top margin to the #main div of 60px it puts a 60px white margin at the top of the whole page (so the background image of the container div starts 50px below the top of the screen). I just want the main div to have a top margin, not the container. I can put a header div in with the same background as the main static bg image but it is not aligned and i'm sure using margins would be a cleaner way to do it. Any ideas? Thanks
October 25, 201016 yr Not sure if you've already sorted this or not. But you need a bit of revision on the css box model. Essentially all elements are contained in a box. Adding a margin adds space outside of this box, so if you have a background color in the box, it won't be shown in the margin. Adding some padding adds space inside the box, so the size of the box becomes whatever size you set it, plus the padding to give a total size. Hope this helps
Create an account or sign in to comment