<div style="float:left">左</div>
<div style="float:left">中</div>
<div style="float:left">右</div>
<div style="float:left">左</div>
<div style="float:right">
<div style="float:left">中</div>
<div style="float:right">右</div>
</div>
<div style="zoom:1; overflow:hidden"> /* 清浮動觸發 BFC */
<div style="float:left">左</div>
<div style="float:left">中</div>
<div style="float:left">右</div>
</div>
overflow:hidden 觸發 BFC 包含浮動子元素,高度自適應。zoom:1 兼容 IE6/7 觸發 hasLayout。| 場景 | 推薦方式 | 理由 |
|---|---|---|
| 無 JS 交互、固定佈局 | 方式一 + 父容器清浮動 | 代碼最少,無嵌套,易響應式改造 |
| 需 JS 動態展開/收縮側欄 | 方式二(左右分離) | 操作區與內容區 DOM 分離,減少重排重繪 |
| 中間自適應、兩側定寬 | 聖杯/雙翼佈局(定位+margin) | 更穩健,避免浮動塌陷問題 |
Flexbox / Grid 佈局已全面普及,新項目首選:
.container { display: flex; }
.left { width: 200px; }
.center { flex: 1; }
.right { width: 200px; }
零浮動、零清浮動、完美自適應,IE10+ 全支持。