左側 float:left 廣告(300×250px),右側文章內容高度超過 250px 時,會繞至廣告下方,導致版面崩壞。
為左側浮動元素外層包一個 div 並設定固定 height(或 min-height),撐開浮動上下文,迫使右側內容維持在右側欄位。
<div class="sidebar-wrapper" style="height: 400px;">
<div class="ad" style="float:left; width:300px; height:250px;">廣告</div>
</div>
<div class="article">文章內容...</div>
.sidebar-wrapper 高度視設計稿而定,需大於等於浮動元素高度。
margin-left: 320px(需知左側寬度)。overflow:hidden、display:flow-root)包含浮動。