I understand that items within a flex container obey different rules for margin collapsing than they normally would (i.e. when not within a flex wrapper). However, the container itself's margins should still behave normally, right? In other words, why are the margins different in the two containers in this CodePen?
h1, h2 {
margin: 2rem 0;
}
.inline-flexed,
.flexed {
margin: 2rem 0;
align-items: center;
}
.inline-flexed {
display: inline-flex;
}
.flexed {
display: flex;
}
.left {
display: inline-block;
width: 2rem;
height: 2rem;
background-color: blue;
}
.right {
line-height: 1.5;
background-color: lightgray;
}
<h1>I have margins!</h1>
<span class="inline-flexed">
<span class="left"></span>
<span class="right">My container is inline-flex'ed. For some reason my parent's container's margins don't collapse.</span>
</span>
<h2>I also have margins!</h2>
<span class="flexed">
<span class="left"></span>
<span class="right">My container is flex'ed. My parent's container's margins collapse as you'd expect.</span>
</span>
<h2>Is this a browser bug?</h2>