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,经测试发现:测试