当前位置:网站首页>On BFC (block formatting context)
On BFC (block formatting context)
2022-04-23 07:36:00 【flym_】
In our development, we often hear BFC The word , When you want me to say BFC What is it? , But it can't explain well , understand . Anyway, there is no clear understanding , I have read the relevant materials carefully in the past two days to deepen my understanding of BFC understand .(BFC yes Web The layout of the box model in the page CSS Rendering mode , It refers to an independent rendering area or an isolated independent container . )
What is? BFC
BFC: Block formatting context (Block Formatting Context,BFC) yes Web Visualization of the page CSS Part of the rendering , It's the area where the layout process of the box takes place , It's also the area where floating elements interact with other elements .
1 BFC It is an independent layout environment , The layout of the elements is not affected by the outside world .
2. If an element matches the trigger BFC Conditions , be BFC The layout of elements in is not externally affected .
3. Floating doesn't affect anything else BFC The layout of the elements in , And clear float can only clear the same BFC The float of the element in front of it .
4. The block formatting context contains everything inside the element that created it .
5. In a BFC in , Block box and row box ( A row box consists of all the inline elements in a row ) Will be arranged vertically along the border of its parent element .
How to form BFC
- Floating elements float The value of the none.
- Absolute positioning elements ( Elemental position by absolute or fixed)
- overflow Values are not for visible The block element of
- display The value is flow-root The elements of
- display The value of is table-cell, table-caption, inline-block Any one of them .
- position The value of the relative and static.
BFC application
- Prevent font wrapping
- Adaptive two ( many ) Column layout
- Clear internal float
- prevent margin overlap
Understand in actual code BFC
1. Make the floating content equal to the surrounding content
In the actual development, we will encounter that the floating element exceeds the height of the parent element .
<style>
.outer {
border: 5px dotted rgb(214,129,137);
width: 450px;
}
.aside {
width: 100px;
height: 150px;
float: left;
background: #f66;
}
.main {
/* height: 200px; */
background: #fcc;
}
</style>
<body>
<div class="outer">
<div class="aside"></div>
<div class="main">I am a floated element.</div>
</div>
</body>
Create one that will contain this float BFC, The usual practice is to set the parent element overflow: auto Or set other non default overflow: visible Value .
.outer {
border: 5px dotted rgb(214,129,137);
width: 450px;
overflow: hidden;
}
2. Don't overlap with floating elements
If a floating element is followed by a non floating element , Then there will be a phenomenon of coverage , Many adaptive two column layouts do this . For example, the effect in the figure below , For example
<style>
.outer {
border: 5px dotted rgb(214,129,137);
width: 450px;
position: relative;
}
.aside {
width: 100px;
height: 150px;
float: left;
background: #f66;
}
.main {
height: 200px;
background: #fcc;
}
</style>
<body>
<div class="outer">
<div class="aside"></div>
<div class="main">I am a floated element.</div>
</div>
</body>
Because of two box All in the same BFC in , It's all about BFC The boundary is the starting point , If two box They all have BFC Words , The layout will be arranged one by one in order , We can trigger main Generate BFC.
.main {
height: 200px;
background: #fcc;
overflow: hidden;
}
版权声明
本文为[flym_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230617476558.html
边栏推荐
猜你喜欢
快速下载vscode的方法
学习笔记5-梯度爆炸和梯度消失(K折交叉验证)
Javscript gets the real suffix of the file
vim+ctags+cscpope开发环境搭建指南
数据分析入门 | kaggle泰坦尼克任务(三)—>探索数据分析
可视化之路(九)Arrow类详解
数论分块(整除分块)
Take you to travel in space, and American photography technology provides comprehensive technical support for aerospace creative applet
免费开源农业物联网云平台(Version:3.0.1)
Solution of self Networking Wireless Communication intercom system in Beifeng oil and gas field
随机推荐
安装tui-editor失败,快速解决方案
Flexible blind patch of ad hoc network | Beifeng oil and gas field survey solution
hql求一个范围内最大值
浅谈BFC(块格式化上下文)
关于'enum'枚举类型以及结构体的问题。
可视化常见问题解决方案(八)共享绘图区域问题解决方案
Transformer的pytorch实现
LATEX公式注意事项
菜菜的并发编程笔记 |(五)线程安全问题以及Lock解决方案
HuggingFace
Applet newline character \ nfailure problem resolution - Daily pit stepping
golang实现正则匹配:密码包含至少一位数字,字母和特殊字符,且长度8-16
[hdu6833]A Very Easy Math Problem(莫比乌斯反演)
学习笔记5-梯度爆炸和梯度消失(K折交叉验证)
数据库查询优化的方式
[LNOI2014]LCA——树链剖分——多点LCA深度和问题
通用型冒泡、选择、插入、希尔、快速排序的代码实现
LATEX使用
MVCC(多版本并发控制)
数据分析学习(一)数据分析和Numpy基础