Reputation: 2402
im trying to add margin-bottom to a div (div.bar) but is breaking the parent div
in this fiddle you can check what im saying.
http://jsfiddle.net/dmsf/2JggY/
but if you add a 1px border to the foo div
.foo {
background-color:#FFF;
border: 1px solid;
margin: 10px;
}
it will work as expected.
it is possible to make it work without the 1px border?
Upvotes: 0
Views: 215
Reputation: 96
It is a case of collapsing margins (http://reference.sitepoint.com/css/collapsingmargins), there are a few ways to fix this, one is to use padding inside of elements. Taking your example and use padding-bottom on .foo instead of a margin bottom on .bar http://jsfiddle.net/davidpett/g2CzH/
.foo {
background-color:#FFF;
margin: 10px;
padding-bottom: 50px;
}
.bar {
height:100px;
background-color:#333;
}
Upvotes: 0
Reputation: 61063
Set {overflow: hidden} or {overflow: auto} on the parent.
.foo {
overflow: auto
}
Upvotes: 2