本文主要是介绍css中的bfc怎么玩?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先弄明白一个概念,上面是bfc?
w3c是这样解释
BFC(Block Formatting Context)是Web页面中盒模型布局的CSS渲染模式。它的定位体系属于常规文档流。
说通俗一点就是:
float的值不为none
position的值不为static或者relative
display的值为 table-cell, table-caption, inline-block, flex, 或者 inline-flex中的其中一个
overflow的值不为visible
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Document</title><style>.column{width: 31.33%;background-color: aqua;float: left;margin: 0.1%;color: #fff;padding: 10px 0;}.column:last-child{float: none;
/* overflow: hidden;*/}</style>
</head>
<body><div class="container"><div class="column">11</div><div class="column">22</div><div class="column">33</div></div>
</body>
</html>
上面的代码添加了overflow:hidden所以会形成一个新的bfc模块。
理解了概念对于很多布局都追根问底,明白其中的原理,比如什么计算margin边距上下取大左右取大。什么左边头像右边文字之类的布局等等。
更多详细介绍见:http://www.w3cplus.com/css/understanding-block-formatting-contexts-in-css.html
这篇关于css中的bfc怎么玩?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!