CSS: Margin-top when parent's got no border

Manny picture Manny · Sep 8, 2009 · Viewed 30k times · Source

As you can see in this picture, I've got an orange div inside a green div with no top border. The orange div has a 30px top margin, but it's also pushing the green div down. Of course, adding a top border will fix the issue, but I need the green div to be top borderless. What could I do?

Thanks

Answer

Fabian picture Fabian · Sep 8, 2009

You could add overflow:auto to .body to prevent margin-collapsing. See http://www.w3.org/TR/CSS2/box.html#collapsing-margins