DEV Community

Cover image for Quick CSS Quiz #1

Quick CSS Quiz #1

Abdelrahman Ismail on September 28, 2018

CSS might be a total mystery to you or a topic that’s near and dear to your heart. Whether you think of CSS as a "necessary evil" or think of it as...
Collapse
 
ismail9k profile image
Abdelrahman Ismail

First of all, because the div is a block-level element it will take the full width of the container, so the distance between the two divs is the vertical distance.
Due to "margin collapsing", the top and bottom margins are collapsed into a single margin whose size is the largest of the individual margins, which is 50px.

Collapse
 
ygalanter profile image
ygalanter

Adjacent margins overlap, not combine, hence 50.

Collapse
 
ismail9k profile image
Abdelrahman Ismail

πŸ˜„πŸ‘πŸ‘πŸŽ‰πŸŽ‰

Collapse
 
maxart2501 profile image
Massimo Artizzu

Hey folks, remember that margin collapsing happens only vertically, or better on the block axis.

Also, it doesn't apply to flex or grid items.

Collapse
 
ismail9k profile image
Abdelrahman Ismail

Thank you for sharing this πŸ€—πŸ€—