Description
“Margin collapse” has a dastardly reputation, one of the trickier parts of CSS. Fortunately, it gets a lot easier once you learn a few rules! In this tutorial, we take a deep dive into the governing p ...
Summary
- This idea might sound simple, but if you've been writing CSS for a while, you've almost certainly been surprised when margins either don't collapse, or they collapse in weird and unexpected ways.
- The negative margins will share a space, and the size of that space is determined by the most significant negative margin.
- By applying an inverse negative margin to the parent, you can "cancel out" a margin.
- No 3D illustration for this one — honestly, it was too busy and chaotic-looking to offer much clarity 😅) Flow layout only So far, all the examples we've seen have assumed that we're "in-flow";