CSS Odd Behavior: min-height and margin collapse -
consider following code:
.container { min-height: 100px; background-color: lightgreen; } p { margin-bottom: 50px; }
<div class="container"> <p>welcome</p> </div> <div class="after"> main content. </div>
question:
mdn's margin collapse page states if there min-height set on parent element, prevent bottom margin adjoining last child's bottom margin - prevent margin collapsing. me, makes sense.
parent , first/last child:
if there no border, padding, inline part, block_formatting_context created or clearance separate margin-top of block margin-top of first child block, or no border, padding, inline content, height, min-height, or max-height separate margin-bottom of block margin-bottom of last child, margins collapse. collapsed margin ends outside parent.
in example, however, devtools shows bottom margin of p tag expected - directly beneath p element - there 50px of blank space below container, doesn't make sense. margin of p tag seems still collapsing somehow, ending outside parent , affecting position of next element, though margin of p , .container not adjoining, , devtools shows p tag's margin near bottom of .container.
anyone have explanations why margin still sort of collapsing , leaving blank space below .container? also, mdn page wrong in saying min-height prevent margin collapse?
thanks
Comments
Post a Comment