Odd CSS behavior: crash of minimum height and fold

Consider the 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>
      

Run code


http://jsfiddle.net/Lp4tp/31/

Question:

MDN's margin antialiasing page states that having a minimum height set on a parent will prevent its bottom margin from shifting off its last child bottom edge - this will prevent a crash. It makes sense to me.

Parent and first / last child:
If no border, padding, inline part, block_formatting_context, created or allowed to separate the top of the box from the top of its first child, or no border, padding, inline content, height, minimum height, or max -height to separate the bottom edge of the box from the bottom edge of its last child, then those margins collapse. The collapsed edge ends outside the parent.

In this example, however, DevTools shows the bottom margin of the p tag where expected - right below the p element, but then there is 50px of free space under the container, which doesn't make sense. The p-tag's limit still collapses, ends outside of the parent and affects the position of the next element, even if the p-field and the .container are not touching, and DevTools shows that the p-tag is nowhere near the bottom of the container.

Does anyone have an explanation as to why the margin still collapses and leaves an empty space at the bottom of the .container? Also, is the MDN page incorrect in stating that the minimum height will prevent the crash?

thank

+3
css margin collapse


source to share


No one has answered this question yet

Check out similar questions:

2241
When to use margin vs padding in CSS
1942
How to move the height: 0; height: auto; using CSS?
787
CSS height 100% with padding / markup
8
CSS Specification 2.1: 8.3.1 Collapsing Fields: Cannot Interpret Correctly Special Case: Clarification Requested
2
The fields are blurred:
2
How do I collapse the edge of inline-block elements?
1
How does parent and first / last child crash work?
1
how does "clear" prevent margin collapse?
1
Damaged stock in CSS
0
Margin collapse and clearance



All Articles
Loading...
X
Show
Funny
Dev
Pics