FC(Formatting Context)格式化内容,常见的FC有BFC、IFC、FFC、GFC四种类型,BFC和IFC是W3C CSS2.1规范提出的概念,FFC和GFC是W3C CSS3规范提出的概念,其实就是定义了一套页面渲染的规则,决定了盒子以什么样的方式渲染从而占据什么样的位置区域,本文只是简单的学习笔记以供参考。

  想要弄懂FC,首先得弄清楚盒子模型,常见的两种盒子模型为:

IE盒子模型(怪异模式):

  width = content-width + padding-width + border-width;

  height = content-height + padding-height + border-height;

W3C盒子模型(标准):

  width = content-width;

  height = content-height;

  IE总是与众不同,让人精疲力尽,好在IE8开始支持CSS3的属性box-sizing:border-box/content-box/inherit;有了这个属性,我们在布局时就游刃有余了,其实这些都是基于BFC的,下面开始进入正文:

BFC(Block formatting contexts):

  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.

  总结要点如下:

  • float 的值不为 none

  • position 的值不为 static 或 relative

  • display 的值为 table-cell、table-caption、inline-block、flex 或 inline-flex

  • overflow 的值不为 visibility

  特点:

  • 块盒子垂直排列,垂直方向上在外边距上会进行塌陷,以大的外边距为二者之间的距离

  • 浮动的块盒子左右外边距也会发生同样的塌陷,以大的外边距为二者之间的距离

IFC(Ininle formatting contexts):

  In an inline formatting context, boxes are laid out horizontally, one after the other, beginning at the top of a containing block. Horizontal margins, borders, and padding are respected between these boxes. The boxes may be aligned vertically in different ways: their bottoms or tops may be aligned, or the baselines of text within them may be aligned. The rectangular area that contains the boxes that form a line is called a line box.

  总结要点如下:

  • 水平方向上排列

  • 行盒子以不同的方式水平对齐,文字的话一般以文字的基线对齐

  • 还有一种特殊的类型是在块盒子里包含着行盒子称作inline-block

  特点:

  • 没有宽度和高度

FFC(Flex formatting contexts):

  Made up of telescopic containers and telescopic items. You can get a telescopic container by setting the display attribute of the element to flex or inline-flex. Containers set to flex are rendered as a block level element, while containers that are set to inline-flex are rendered as inline elements.

  总结要点如下:

  • 自适应上下文,俗称弹性盒模型

  • display属性值为flex或inline-flex时即可实现块盒子和行盒子

  特点:

  • 可伸缩性的盒子,盒子内外都不受影响,任意实现复杂布局

GFC(Gird formatting contexts):

  When set to a display element value of grid, this element will get an independent rendering area, we can in the grid container (grid container) defined on the grid definition line (grid definition rows) and grid (grid definition columns) as defined in the attributes of each grid project (grid item) on the definition the grid line (grid row) and grid column (grid columns) for each grid project (grid item) defines the location and space.

  总结要点如下:

  • 网络式布局,真正的二维空间布局

  • display属性值为gird时即可实现网络布局,在网格容器的行列上再次进行行列布局

  特点:

  • 二维布局,适用于超级复杂的两个维度布局

  常用的四种布局方式,要知其然并知其所以然,CSS规范博大精深,前端路上还需不断学习巩固加深!

  谈到了FC,必然会提到多栏自适应布局,下面简单介绍常用的几种方法:

1.float+margin实现两栏布局:

样式:
.box {
width: 500px;
height: 200px;
margin: 100px auto;
border: 1px solid red;
}
.left {
width: 200px;
height: 200px;
float: left;
background-color: red;
}
.right {
margin-left: 200px;
background-color: green;
height: 200px;
}
布局:
<div class="box">
<div class="left"></div>
<div class="right"></div>
</div>

  效果如下:

2.float+overflow实现两栏布局:

样式:
.box {
width: 500px;
height: 200px;
margin: 100px auto;
border: 1px solid red;
}
.left {
width: 200px;
height: 200px;
float: left;
background-color: red;
}
.right {
overflow: hidden;
background-color: green;
height: 200px;
}
布局:
<div class="box">
<div class="left"></div>
<div class="right"></div>
</div>

  效果如下:

3. float+overflow实现三栏布局:

样式:
.box {
width: 500px;
height: 200px;
margin: 100px auto;
border: 1px solid red;
}
.left {
width: 200px;
height: 200px;
float: left;
background-color: red;
}
.middle {
height: 200px;
overflow: hidden;
background-color: yellow;
}
.right {
width: 200px;
height: 200px;
float: right;
background-color: green;
}
布局:
<div class="box">
<div class="left"></div>
<div class="right"></div>
<div class="middle"></div>
</div>

   效果如下:

  有了这些认识之后,你应该对多栏自适应布局游刃有余了吧,下次面试官问你BFC、IFC时,千万别说没听过哦!

你知道BFC、IFC、FFC、GFC及多栏自适应布局吗?的更多相关文章

  1. 【转】CSS深入理解流体特性和BFC特性下多栏自适应布局

    这篇文章发布于 2015年02月12日,星期四,23:36,归类于 css相关. 阅读 30873 次, 今日 63 次 by zhangxinxu from http://www.zhangxinx ...

  2. CSS深入理解流体特性和BFC特性下多栏自适应布局

    一.块状元素的流体特性与自适应布局 块状元素像放在容器中的水流一样,内容区域会随着margin, padding, border的出现自动填满剩余空间,这就是块状元素的流体特性. 来一个小实验: di ...

  3. BFC特性下多栏自适应布局

    BFC 已经是一个耳听熟闻的词语了,网上有许多关于 BFC 的文章,介绍了如何触发 BFC 以及 BFC 的一些用处(如清浮动,防止 margin 重叠等).虽然我知道如何利用 BFC 解决这些问题, ...

  4. BFC之宽度自适应布局篇

    说到自适应布局,我们曾在“抛砖引玉之宽度自适应布局”一文中学习过.当时的核心思想主要是利用float+margin的形式.利用块状元素的流体特性,然后计算出float元素的宽度,并赋予到块状元素的相应 ...

  5. BFC,IFC,GFC,FFC的定义及功能

    What's FC?一定不是KFC,FC的全称是:Formatting Contexts,是W3C CSS2.1规范中的一个概念.它是页面中的一块渲染区域,并且有一套渲染规则,它决定了其子元素将如何定 ...

  6. 初识 BFC、 IFC、GFC、FFC

    首先本文中介绍的 BFC. IFC.GFC.FFC 均为 CSS 中常见问题的解读,如没兴趣,可以绕道了. 然后在介绍这么多的 *FC 之前,我们得了解 一下 Box 和 Formatting Con ...

  7. 【转】前端的BFC、IFC、GFC和FFC

    什么是BFC.IFC.GFC和FFC CSS2.1中只有BFC和IFC, CSS3中才有GFC和FFC. FC的全称是:Formatting Contexts,是W3C CSS2.1规范中的一个概念. ...

  8. 什么是BFC、IFC、GFC和FFC

    什么是BFC.IFC.GFC和FFC CSS2.1中只有BFC和IFC, CSS3中才有GFC和FFC. FC的全称是:Formatting Contexts,是W3C CSS2.1规范中的一个概念. ...

  9. css3中的BFC,IFC,GFC和FFC

    出处:https://www.jianshu.com/p/e75f351e11f8 表格比较: 名称 英文全称 含义 BFC Block Formatting Contexts 块级格式化上下文 IF ...

随机推荐

  1. 【Android Studio快捷键】之导入对应包声明(import packages)

    可能import 单个声明的快捷键大家都非常easy找到.Alt+Enter.可是假设我要一次性import文件里全部的声明.这个快捷键是什么呢,找啊找的,就是没找到,曾经在Eclipse是Ctrl+ ...

  2. AB串

    题目: 给定n个A和2n个B.用这些字符拼成一个字符串.要求这个串的全部前缀和后缀B的个数始终不少于A. (一个字符串的前缀是仅仅从开头到某个位置为止的子串,后缀是仅仅从某个位置到结尾的子串). 输入 ...

  3. spool命令、创建一个表,创建而且copy表,查看别的用户下的表,rowid行地址 索引的时候使用,表的增删改查,删除表,oracle的回收站

      1.spool命令 spool "D:\test.txt" spool off SQL> host cls 2.创建一个表 SQL> --条件(1):有创建 ...

  4. Woody的Python学习笔记1

    Python 是一种解释性语言:这意味着开发过程中省去了编译这个环节,类似于PHP\Perl. Python 是交互式语言:这意味着你能够在一个python提示符,直接互动运行写你的程序. Pytho ...

  5. Shiro学习(一)总体介绍

    1.1  简介 Apache Shiro是Java的一个安全框架.目前,使用Apache Shiro的人越来越多,因为它相当简单,对比Spring Security,可能没有Spring Securi ...

  6. 超详细的 Linux CentOS 编译安装python3

    前言: 安装完CentOS7后,执行#Python与#python -V,看到版本号是2.6,而且之前写的都是跑在python3.X上面的,3.X和2.X有很多不同,在这里我就不弊述两者之间的区别了新 ...

  7. JavaScript导航树

    JS导航树 整理之前的小代码片段,放到博客,便于以后完善查看: 该JS导航树实际效果,[GSP+社区网站专题课程页面导航树]地址:http://gsp.inspur.com/knowledge/zhu ...

  8. 《Head First 设计模式》【PDF】下载

    <Head First 设计模式>[PDF]下载链接: https://u253469.ctfile.com/fs/253469-231196307 First 设计模式>[PDF] ...

  9. iOS 数据储存--SQLite 操作数据库-FMDB,sqlite数据类型,保存图片,demo

    1.SQLite 语句中 数据类型的储存 /* 不区分大小写 char(长度).字符串 NULL. 空值 INTEGER. 整型 REAL.浮点型 TEXT.文本类型 BLOB. 二进制类型,用来存储 ...

  10. 程序员的自我救赎---11.4:FileSystem文件服务

    <前言> (一) Winner2.0 框架基础分析 (二)PLSQL报表系统 (三)SSO单点登录 (四) 短信中心与消息中心 (五)钱包系统 (六)GPU支付中心 (七)权限系统 (八) ...