HTML DOM Style marginBottom 屬性

2018-08-04 20:41 更新

Style marginBottom 屬性

Style 對(duì)象參考手冊(cè) Style 對(duì)象

定義和用法

marginBottom 屬性設(shè)置或返回元素的下外邊距。

語(yǔ)法

設(shè)置 marginBottom 屬性:

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

返回 marginBottom 屬性:

Object.style.marginBottom

描述
% 定義基于父元素寬度的百分比下外邊距。
length 使用 px、cm 等單位定義下外邊距的寬度。
auto 瀏覽器設(shè)定的下外邊距。
inherit 下外邊距從父元素繼承。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持 marginBottom 屬性。

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


提示和注釋

margin 屬性和 padding 屬性都是在元素周圍插入空間。然而,不同的是,margin 將圍繞邊框外面插入空間,padding 將在元素邊框內(nèi)插入空間。


實(shí)例

實(shí)例

更改 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 對(duì)象參考手冊(cè) Style 對(duì)象
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)