margin-bottom
margin-bottom
CSS 데모: margin-bottom 데모 버튼을 클릭해 보세요!
selector {
    margin-bottom:  <길이> | <퍼센트(%)> | auto
}
/* <길이> 단위 값 */
margin-bottom: 20px;
margin-bottom: 3em;
margin-bottom: -20px; /* 음수 값 허용 */
margin-bottom: -3em; /* 음수 값 허용 */

/* <퍼센트(%)> 단위 값 */
margin-bottom: 10%; /* 컨테이닝 블록 너비의 10% */
margin-bottom: 50%; /* 컨테이닝 블록 너비의 50% */
margin-bottom: -10%; /* 음수 값 허용 */
margin-bottom: -50%; /* 음수 값 허용 */

/* 키워드 값 */
margin-bottom: auto;

/* 전역 값 */
margin-bottom: inherit;
margin-bottom: initial;
margin-bottom: revert;
margin-bottom: revert-layer;
margin-bottom: unset;
<h3>h3</h3>
<h4>h4</h4>
<h5>h5</h5>
<p>p</p>
<ul>
    <li>ul</li>
</ul>
<ol>
    <li>ol</li>
</ol>
<dl>
    <dt>dl</dt>
</dl>
<hr>
<figure>figure</figure>
<menu>
    <li>menu</li>
</menu>
<blockquote>blockquote</blockquote>
실제 적용된 모습
<p>margin-bottom이 지정되지 않은 문단입니다.</p>
<p class="ex-1">margin-bottom이 50px인 문단입니다.</p>
<p>margin-bottom이 지정되지 않은 문단입니다.</p>
.ex-1 {
    margin-bottom: 50px;
    color: red;
}
실제 적용된 모습
<div class="box me">나</div>
<div class="box sibling">형제 요소</div>
.me {
    margin-bottom: -50px; /* 음수 값을 사용 */
    border: 3px dashed #663399;
    background: #ffd9f7;
}
.box {
    width: 200px;
    height: 150px;
}
.sibling {
    border: 3px dashed gray;
    background: rgba(0, 0, 0, 0.2);
}
실제 적용된 모습 인접한 아래쪽의 요소와 겹친 모습을 볼 수 있습니다.
<div class="box flex-box">
    <p>플렉스 박스의 아이템입니다. margin-bottom: auto가 적용됩니다.</p>
</div>
<div class="box grid-box">
    <p>그리드 박스의 아이템입니다. margin-bottom: auto가 적용됩니다.</p>
</div>
.flex-box {
    display: flex;
    align-items: flex-end;
}
.grid-box {
    display: grid;
    align-items: end;
}
.box {
    height: 120px;
    background: gold;
}
.box + .box {
    margin-top: 1em;
}
p {
    background: yellowgreen;
    margin-top: 0;
    margin-bottom: auto; /* 플렉스 박스나
                            그리드 박스의 아이템일 경우에만 작동 */
}
실제 적용된 모습
<div class="box box-1">box-1</div>
<div class="box box-2">box-2</div>
.box {
    width: 100px;
    height: 100px;
    background: orange;
}
.box-1 {
    margin-bottom: 50px;
}
.box-2 {
    margin-top: 100px;
}
실제 적용된 모습
<p>부모 요소에 padding-bottom이나 border-bottom이 없을 때</p>
<div class="parent parent-1">
    <div class="child">child</div>
</div>
<p>부모 요소에 padding-bottom이나 border-bottom이 있을 때</p>
<div class="parent parent-2">
    <div class="child">child</div>
</div>
.parent-1 {
    margin-bottom: 30px; /* 부모 요소와 자식 요소의 '마진 상쇄(margin collapsing)'가 발생합니다. */
}
.parent-2 {
    border-bottom: 2px solid red;
}
.parent {
    background: silver;
    height: auto;
}
.child {
    width: 100px;
    height: 100px;
    background: gold;
    margin-bottom: 50px;
}
실제 적용된 모습