轻松上手,快乐学习!

Style marginBottom 属性


实例

更改 div 元素的下边距:

document.getElementById("myDiv").style.marginBottom = "50px";
亲自试一试 »

定义和用法

marginBottom 属性设置或返回元素的下外边距。

提示: margin 属性和 padding 属性都是在元素周围插入空间。然而,不同的是,margin 将围绕边框外面插入空间,padding 将在元素边框内插入空间。


浏览器支持

属性
marginBottom Yes Yes Yes Yes Yes

语法

返回 marginBottom 属性:

object.style.marginBottom

设置 marginBottom 属性:

object.style.marginBottom = "%|length|auto|initial|inherit"

属性值

描述
% 定义基于父元素宽度的百分比下外边距。
length 使用 px、cm 等单位定义下外边距的宽度。
auto 浏览器设定的下外边距。
initial 设置该属性为它的默认值。请参阅 initial
inherit 从父元素继承该属性。请参阅 inherit

技术细节

默认值: 0
返回值: 一个字符串,表示元素的底边距
CSS 版本 CSS1

更多实例

实例

将 <div> 元素的底部边距更改回 "normal":

document.getElementById("myDiv").style.marginBottom = "0px";
亲自试一试 »

实例

返回 <div> 元素的下边距:

alert(document.getElementById("myDiv").style.marginBottom);
亲自试一试 »

实例

对比 marginBottom 和 paddingBottom 之间的差异:

function changeMargin() {
  document.getElementById("myDiv").style.marginBottom = "100px";
}

function changePadding() {
  document.getElementById("myDiv2").style.paddingBottom = "100px";
}
亲自试一试 »

相关页面

CSS 教程: CSS Margin

CSS 参考手册: margin-bottom 属性

HTML DOM 参考手册: margin 属性


❮ Style 对象