margin collapsing in css

Posted by  Ankit Singh
 1552  View(s)
Ratings:
Rate this:
Hi Expert,

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

Thanks in advance.
  1. Re: margin collapsing in css

    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.

      Modified On Mar-30-2018 03:56:06 AM

Answer