當兩個垂直相鄰的區塊級元素,彼此沒有 border、padding、inline content、clearance隔開時,它們的 margin-top 與 margin-bottom 會合併為單一外邊距,大小取兩者之最大值(若有負值則相加後取最大)。
border、padding、overflow:hidden/auto/scroll、display:flow-root、float、position:absolute/fixed、flex/grid 容器。<html> 的 margin 不與內容合併。margin 控制模組間距,導致不可預期的合併。<div> 或 <br>。padding 建立容器內部呼吸空間(不參與合併)。border 或 overflow:hidden 建立 BFC(區塊格式化上下文)阻隔合併。margin-bottom 或只設 margin-top,消除合併歧義。理解合併機制、善用 BFC 與單向外距,能讓版面間距可預測、可維護,回歸 W3C 盒模型設計初衷。