Why can BFC solve the margin overlay problem?
phpcn_u1582
phpcn_u1582 2017-05-19 10:25:45
0
1
692

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_u1582
phpcn_u1582

reply all(1)
曾经蜡笔没有小新

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template