HTML & CSS · Senior · Question 27 of 75

What conditions make the vertical margins of a parent and its first child collapse?

Explanation

The first child's margin-top "falls through" outside the parent if nothing separates them. Collapsing is prevented by padding or border on the parent, display: flow-root, or a flex/grid container - margins inside those never collapse. With negative values, the result is the largest positive plus the most negative.

Further reading

Problem with a question

HTML & CSS · Senior · question 27

Test yourself

Take the HTML & CSS · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz