codecamp

HTML DOM Style marginBottom 属性

Style marginBottom 属性

Style 对象参考手册 Style 对象

定义和用法

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

语法

设置 marginBottom 属性:

Object.style.marginBottom="%|length|auto|inherit"

返回 marginBottom 属性:

Object.style.marginBottom

描述
% 定义基于父元素宽度的百分比下外边距。
length 使用 px、cm 等单位定义下外边距的宽度。
auto 浏览器设定的下外边距。
inherit 下外边距从父元素继承。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 marginBottom 属性。

注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有规定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。


提示和注释

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


实例

实例

更改 div 元素的下外边距:

<html>
<head>
<style type="text/css">
#ex1
{
border: 1px solid #FF0000;
}
</style>
<script>
function displayResult()
{
document.getElementById("ex1").style.marginBottom="100px";
}
</script>
</head>
<body>

<div id="ex1">This is some text.</div>
<br>
<button type="button" onclick="displayResult()">Change bottom margin</button>

</body>
</html>

尝试一下 »


Style 对象参考手册 Style 对象
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

HTML DOM对象

HTML DOM 引用对象

HTML DOM Password 对象

HTML DOM Link 对象

HTML DOM Select 对象

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }