BFC 的擴寫是 Block formatting contexts (塊級格式化上下文),它看不見摸不着但對 CSS 盒模型有影響。
標準裏對 BFC 的描述是:html
Floats, absolutely positioned elements, block containers (such as inline-blocks, table-cells, and table-captions) that are not block boxes, and block boxes with 'overflow' other than 'visible' (except when that value has been propagated to the viewport) establish new block formatting contexts for their contents.
同時提到一個前端常見的 collapse 現象:前端
Vertical margins between adjacent block-level boxes in a block formatting context collapse.
因此筆者是這麼理解 BFC 的:git
也就是說不一樣的 BFC之間就會消除相鄰元素的 collapse,如下是可建立 BFC 的條件:github
這裏寫了個測試 collapse 的 demo,經測試發現:測試