美文网首页
深入了解BFC

深入了解BFC

作者: same | 来源:发表于2017-02-22 12:12 被阅读7次

1.什么是BFC?

再解释BFC之前先要解释Box,Formatting Contex。

Box

Block-level elements are those elements of the source document that are formatted visually as blocks (e.g., paragraphs). The following values of the ‘display’ property make an element block-level: ‘block’, ‘list-item’, and ‘table’.

块级元素是那种源文档被格式化为可视块了的元素,然后使这个元素变成块级元素的display属性取值如下: ‘block’, ‘list-item’, 和 ‘table’。

Formatting context

Formatting context 是 W3C CSS2.1 规范中的一个概念。它是页面中的一块渲染区域,并且有一套渲染规则,它决定了其子元素将如何定位,以及和其他元素的关系和相互作用。最常见的 Formatting context 有 Block fomatting context (简称BFC)和 Inline formatting context (简称IFC)。

BFC

BFC(Block formatting contex)直译为块级格式化上下文。它是一个独立的渲染区域,只有Block-level box参与, 它规定了内部的Block-level Box如何布局,并且与这个区域外部毫不相干。

2.什么情况生成BFC?

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.

大致意思:浮动元素、绝对定位元素,不是块级盒的块级包含块(比如inline-block、table-cell、table-capation)和overflow值不为visible的块级盒子为它们的内容建立了一个新的块级格式化上下文。

以下情况会生成BFC

 根元素

float属性不为none

 position为absolute或fixed

display为inline-block, table-cell, table-caption, flex, inline-flex

overflow不为visible

3.BFC的布局规则

内部的Box会在垂直方向,一个接一个地放置。

Box垂直方向的距离由margin决定。属于同一个BFC的两个相邻Box的margin会发生重叠

每个元素的margin box的左边, 与包含块border box的左边相接触(对于从左往右的格式化,否则相反)。即使存在浮动也是如此。

BFC的区域不会与float box重叠。

BFC就是页面上的一个隔离的独立容器,容器里面的子元素不会影响到外面的元素。反之也如此。

计算BFC的高度时,浮动元素也参与计算

4.BFC的一些应用

①自适应两栏布局

5.参考文章

相关文章

  • 深入了解BFC

    1.什么是BFC? 再解释BFC之前先要解释Box,Formatting Contex。 Box Block-le...

  • BFC原理

    BFC是什么? 了解BFC之前,先了解Box,Formatting Content的概念 Box:CSS布局的基本...

  • BFC

    一、BFC是什么 BFC(box formatting context),要了解BFC是什么需要先理解box和fo...

  • 了解BFC

    1. 什么是BFC BFC:(block formatting context),块格式化上下文。平常基本不使用,...

  • 10 个 CSS 高频面试题,你都会吗?

    了解更多添加697763012 1.什么是 BFC机制 BFC(Block Formatting Context)...

  • BFC

    什么是BFC在了解BFC之前,需要了解一下 Box、Formatting Context的概念。 Box: CSS...

  • CSS新手向的知识点<四>

    阅读本篇文章,你将大致了解到BFC的作用 关于BFC的知识 BFC(block formatting contex...

  • BFC 记录

    一文了解bfc BFC定义bfc(box formatting context) 中文名为块级格式化上下文。在介绍...

  • 关于CSS的BFC

    参考:理解CSS布局和BFCCSS深入理解流体特性和BFC特性下多栏自适应布局 1、概念BFC(Block For...

  • BFC

    原文:[布局概念] 关于CSS-BFC深入理解 面试的时候尽量不讲定义,而是讲例子。 定义 BFC全称叫做(Blo...

网友评论

      本文标题:深入了解BFC

      本文链接:https://www.haomeiwen.com/subject/guapwttx.html