CSS layout: BFC, Grid and centeringCSS 布局:BFC、Grid 与居中

The guide measures the boxes for you and switches their rules on and off. You can also inspect a box in your browser’s developer tools.

说明面板会替你测量这些盒子,并把它们的规则关掉或打开。你也可以用浏览器的开发者工具检查任意一个盒子。

Inside one BFC, top and bottom margins overlap同一个 BFC 里,上下外边距会重叠

overflow: hidden makes each box a BFC of its own, so the margins no longer overlapoverflow: hidden 让每个盒子自成一个 BFC,外边距不再重叠

Box model: with no padding or border, border-box is the same size as the default content-box盒模型:没有内边距和边框时,border-box 和默认的 content-box 一样大

A BFC wraps around the floats inside itBFC 会包住里面的浮动元素

A BFC does not overlap a float beside itBFC 不和旁边的浮动元素重叠

I am a left-floated element我是一个左浮动的元素
I don’t float, but overflow: hidden makes me a BFC, so I sit beside the float. Without it, I start under the float, and my text wraps around it.我没有浮动,但 overflow: hidden 让我自成一个 BFC,所以排在浮动元素旁边。 去掉 overflow: hidden,我就会从浮动元素下面开始排,文字绕着它走。

Explicit formatting context: flow-root显式创建格式化上下文:flow-root

Contains the float without clipping.包住浮动元素,而不裁剪任何内容。