Home > DeveloperSection > Forums > margin collapsing in css
Ankit Singh

Total Post:341

Points:2389
Posted on    June-14-2013 9:29 AM

 CSS-CSS3 CSS-CSS3 
Ratings:


 1 Reply(s)
 768  View(s)
Rate this:
Hi Expert,

what is margin collapsing in CSS. Can you provide any example.

Thanks in advance.


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-15-2013 5:05 AM

In CSS, margin collapsing occurs when the top or bottom margin of one element comes into contact with the top or bottom margin of another element. The concept is simple: The smaller of the two margins is reduced to zero; if both element margins are the same length, then one of the margins is reduced to zero. 

#top
{
margin: 20px;
}

#bottom
{
margin: 10px; 
}

<div id="top"></div>
<div id="bottom"></div>

You can see the most common form of margin collapsing; the top margin of one element comes into contact with the bottom margin of another element. When this happens, the element with the bigger margin wins.


Don't want to miss updates? Please click the below button!

Follow MindStick