In The Zen of CSS Design – Visual Enlightment for The Web on page 82 there is a discussion about collapsing margins and I think this fix will answer your question
Quote;
A somewhat obscure quirk of the CSS box model is someting called collapsing margins. This means that if two elements rest one on top of the other and they both have non-zero margins and no padding, borders
, or other conditions mentioned, the total combined height of both margins will be to less than their sum. So 20px margins won’t add up to a 40px gap between elements a€?? instead each margin collapses into the other and you end up with a 20px gap.
But what does this have to do with the gap problem? Collapsing affects parent and child elements equally; because the div
have no vertical margins
, each div’s bottom margin collapses into its last child paragraph’s bottom margin. But because the total margin value is not zero, the paragraph’s 10px margin still has to be honored. It pokes through the bottom of the containing div
The problem is easy to fix once the diagnosis is made: When a slight 1px vertical padding value is applied to the divs themselves, the conditions for margin collapsing are no longer met and the gaps disappear:
#yourDiv {
background: #fff;
margin: 0;
padding: 1px 0;
width: 350px;
}
HTH