<div style="margin-bottom: 20px">위 박스</div>
<div style="margin-top: 30px">아래 박스</div>
이런 상황에서 예상하면:
실제로는:
마진 병합이 일어나는 주요 상황:
1. 인접 형제 요소들 사이
<p style="margin: 20px">첫 번째 문단</p>
<p style="margin: 30px">두 번째 문단</p>
<!-- 간격은 30px이 됨 -->
<div style="margin-top: 50px">
<p style="margin-top: 20px">자식 문단</p>
</div>
<!-- 위쪽 마진은 50px이 됩니다 -->
/* 이런 상황을 피하기 위해 */
.title {
margin-bottom: 20px;
}
.subtitle {
margin-top: 10px;
}
/* 한쪽으로만 마진을 주는 것이 좋습니다 */
.title {
margin-bottom: 20px;
}
.subtitle {
/* margin-top 제거 */
}