了解BFC

作者: Grit0821 | 来源:发表于2019-04-03 19:54 被阅读0次

1. 什么是BFC

BFC:(block formatting context),块格式化上下文。
平常基本不使用,纯面向面试。
一个块格式化上下文由以下之一创建:

  • 浮动元素 (元素的 float 不是 none)
  • 绝对定位元素 (元素具有 position 为 absolute 或 fixed)
  • 内联块 (元素具有 display: inline-block)
  • 表格单元格 (元素具有 display: table-cell,HTML表格单元格默认属性)
  • 表格标题 (元素具有 display: table-caption, HTML表格标题默认属性)
  • 有overflow 且值不是默认 visible 的块元素,
  • display: flow-root(最新属性,可避免带来其他的副作用)

BFC元素特性表现原则就是,内部子元素再怎么翻江倒海都不会影响外部的元素。

2. BFC的实例(面试)

1. 爸爸管住儿子

用 BFC 包住浮动元素。(这不是清除浮动,.clearfix 才是清除浮动)

.baba{
  border: 10px solid red;
  min-height: 10px;
  display: flow-root; /*触发BFC*/

}
.erzi{
  background: green;
  float:left;
  width: 300px;
  height: 100px;
}

http://js.jirengu.com/rozaxufetu/1/edit?html,css,output

2. 同级兄弟划清界限

用 float + div 做左定宽右自适应布局

.gege{
  width: 100px;
  min-height: 200px;
  border: 3px solid red;
  float: left;
  margin-right: 20px;
}

.didi{
  min-height: 200px;
  border: 5px solid green;
  display: flow-root;
  
}

http://js.jirengu.com/kuhis/1/edit

相关文章

  • 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) 中文名为块级格式化上下文。在介绍...

  • 今天我们来聊聊BFC吧

    一、BFC是什么?在解释 BFC 是什么之前,我们先来了解下Box、Formatting Context是什么?1...

  • CSS深入浅出-关于BFC

    BFC导读 名称 英文全称:Block Formatting Context中文名:块格式化上下文 在了解BFC之...

  • 说人话,解释BFC以及讲述BFC的应用

    初步了解定义 请先耐心阅读BFC的定义和构成前提,然后再看它的作用。 BFC全名:Block Formatting...

网友评论

    本文标题:了解BFC

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