关于css中BFC的理解

1.BFC的理解:块格式化上下文
2.BFC 特性(功能):
(1).使用BFC可以取消盒子margin塌陷(overflow: hidden);
(2).阻止元素被浮动元素覆盖(overflow: hidden)。
3.创建 块格式化上下文 BFC 的方式:
--). 浮动元素(元素的 float 不是 none)
--). 绝对定位元素(元素的 position 为 absolute 或 fixed)
--). 行内块元素(元素的 display 为 inline-block)
--). 表格单元格(元素的 display为 table-cell,HTML表格单元格默认为该值)
--). 表格标题(元素的 display 为 table-caption,HTML表格标题默认为该值)
--). 匿名表格单元格元素(元素的 display为 table、table-row、 table-row-group、table-header-group、table-footer-group(分别是HTML table、row、tbody、thead、tfoot的默认属性)或 inline-table)
--). overflow 值不为 visible 的块元素
--). display 值为 flow-root 的元素
--). contain 值为 layout、content或 paint 的元素
--). 弹性元素(display为 flex 或 inline-flex元素的直接子元素)
--). 网格元素(display为 grid 或 inline-grid 元素的直接子元素)
--). 多列容器(元素的 column-count 或 column-width 不为 auto,包括 column-count 为 1)
--). column-span 为 all 的元素始终会创建一个新的BFC,即使该元素没有包裹在一个多列容器中(标准变更,Chrome bug)
4.BFC的作用:
--). 用来清除浮动。
--). 用来布局
--). 解决margin叠加问题。

下面来看代码,以更好的说明问题:


 

你可能感兴趣的:(关于css中BFC的理解)