--- title: margin-bottom slug: Web/CSS/margin-bottom tags: - CSS - CSS Property - Reference - 'recipe:css-property' translation_of: Web/CSS/margin-bottom ---
margin-bottom は CSS のプロパティで、要素の下側のマージン領域を設定します。正の数を指定すると、隣との間が遠くなるように配置され、負の数を指定すると、近くなるように配置します。
このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 https://github.com/mdn/interactive-examples をクローンしてプルリクエストを送信してください。
このプロパティは、 {{HTMLElement("span")}} または {{HTMLElement("code")}} のような非置換のインライン要素には効果がありません。
/* <length> 値 */ margin-bottom: 10px; /* 絶対的な寸法 */ margin-bottom: 1em; /* 文字の寸法からの相対 */ margin-bottom: 5%; /* 直近のブロックコンテナーの幅からの相対 */ /* キーワード値 */ margin-bottom: auto; /* グローバル値 */ margin-bottom: inherit; margin-bottom: initial; margin-bottom: unset;
margin-bottom プロパティは auto キーワード、または <length> や <percentage> で指定されます。正の数、ゼロ、負の数が指定できます。
auto{{cssinfo}}
<div class="container"> <div class="box0">Box 0</div> <div class="box1">Box 1</div> <div class="box2">Box one's negative margin pulls me up</div> </div>
div に margin-bottom と height を設定する CSS です。
.box0 {
margin-bottom:1em;
height:3em;
}
.box1 {
margin-bottom:-1.5em;
height:4em;
}
.box2 {
border:1px dashed black;
border-width:1px 0;
margin-bottom:2em;
}
包含要素と div の定義の一部です。これによって margin の効果がより明確に見えます。
.container {
background-color:orange;
width:320px;
border:1px solid black;
}
div {
width:320px;
background-color:gold;
}
{{ EmbedLiveSample('Setting_positive_and_negative_bottom_margins',350,200) }}
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName('CSS3 Box', '#propdef-margin-bottom', 'margin-bottom')}} | {{Spec2('CSS3 Box')}} | 目立った変更なし。 |
| {{SpecName('CSS2.1', 'box.html#margin-properties', 'margin-bottom')}} | {{Spec2('CSS2.1')}} | CSS1 と同様、ただしインライン要素での効果は削除。 |
| {{SpecName('CSS1', '#margin-bottom', 'margin-bottom')}} | {{Spec2('CSS1')}} | 初回定義 |
{{Compat("css.properties.margin-bottom")}}