search

Home  >  Q&A  >  body text

Why can BFC solve the margin overlay problem?

http://jsfiddle.net/gothic/B6E8F

It does not mean that the vertical margins of two or more adjacent block elements in ordinary flows will collapse. So which condition does this example violate?

phpcn_u1582phpcn_u15822749 days ago700

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:27:45

    w3.org Specification on margin merging

    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

    • ...

    Margin needs to belong to the block-level box in the same BFC, overflow: hidden A new BFC is created, so it will not collapse naturally.

    reply
    0
  • Cancelreply