Weird overflow

I'm confused: why is there an overflow and the scrollbar is displayed? The container only has a height of 20% and the margin is 2rem, which is way below the viewport height, right? https://jsfiddle.net/KonerDev/u8jb3fmk/4/ In the devtools it looks like the body has been shifted down by 2rem. I'd like to understand what's causing this problem? If I set the 2rem as padding on the body, everything works as intended.
Edit fiddle - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
No description
2 Replies
Koner
KonerOP3w ago
Is this happening because of margin collapsing?
Ray
Ray3w ago
Your top-margin of 2rem, specifically, is what's making the overflow happen. When you set that to 0, the overflow's gone. I'm not totally sure here but I think it's safe to say it likely is related to margin-collapsing, yeah

Did you find this page helpful?