concept
margin-collapse — CSS reference
In ordinary block layout adjoining block-axis margins may combine. Positive margins take the largest; a mixed set adds the largest positive and most negative; all-negative takes the most negative. Sibling, parent-child and empty-block cases have conditions. Flex and grid item margins do not collapse. A new formatting context can prevent parent-child collapse, not necessarily sibling collapse.
Formal Syntax & Structure
css syntaxcss
adjoining in-flow block marginsWorking Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS box geometry lab</title><style>body {margin:0} .sample {background:#dcebe9;color:#182e32}#p{display:flow-root} #a,#b,#c{height:20px} #a{margin-bottom:30px} #b{margin-top:20px;margin-bottom:30px} #c{margin-top:-10px} #flex{display:flex;flex-direction:column} #d{height:20px;margin-bottom:30px} #e{height:20px;margin-top:20px}</style><body><div id="p"><div id="a"></div><div id="b"></div><div id="c"></div></div><div id="flex"><div id="d"></div><div id="e"></div></div></body></html>