MARGIN COLLAPSING IN CSS

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 1017  View(s)
Ratings:
Rate this:
Hi Expert,

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

Thanks in advance.
  1. AVADHESH PATEL

    Post:604

    Points:4228
    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!