首先弄明白一個概念,上面是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