Why are my div margins overlapping and how can I fix it?

后端 未结 5 821
故里飘歌
故里飘歌 2020-11-27 15:42

I don\'t understand why the margins of these divs are overlapping.

5条回答
  •  北海茫月
    2020-11-27 16:21

    I think it's a collapsed margin. Only the largest margin between the bottom of the first element and the top of the second is taken into account.

    It is quite normal to don't have too much space between two paragraphs eg.

    You cannot avoid that with two adjacent elements so you have to enlarge or reduce the larger margin.

    EDIT: cf. W3C

    Two margins are adjoining if and only if:

    • both belong to in-flow block-level boxes that participate in the same block formatting context
    • no line boxes, no clearance, no padding and no border separate them
    • both belong to vertically-adjacent box edges

    So there is no collapsing with float which takes the element out of the flow.

提交回复
热议问题