View Full Version : Margin-top to a block affects to the container div.

07-01-2010, 07:28 PM

I have this page (tirengarfio.com).

I want to give a margin-top to the logo, but when i do it, the div that contains the logo goes also down, why?



07-01-2010, 08:25 PM
That's because of the "collapsing margins" in the CSS box model:

Look at topic 8.3.1 "Collapsing margins"

Vertical margins may collapse between certain boxes:

* Two or more adjoining vertical margins of block boxes in the normal flow collapse. The resulting margin width is the maximum of the adjoining margin widths. In the case of negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum of the positive adjoining margins. If there are no positive margins, the absolute maximum of the negative adjoining margins is deducted from zero.

So, basically, they're sharing.

You can just use padding-top to get the same effect without the dropdown issue caused by margin collapsing.

07-02-2010, 01:02 PM

This is because you have used display:block in #logo img {} css, remove display block from your logo image part, then your margin will affect correctly without affecting the overall Div or Container


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum