1. 程式人生 > 實用技巧 >HTML DOM Style marginBottom 屬性 - Break易站

HTML DOM Style marginBottom 屬性 - Break易站

[

Style marginBottom 屬性
Style 物件

定義和用法

marginBottom 屬性設定或返回元素的下外邊距。

語法

設定 marginBottom 屬性:

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

返回 marginBottom 屬性:

Object.style.marginBottom

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

瀏覽器支援

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

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

提示和註釋

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

例項

例項

更改 div 元素的下外邊距:


<!DOCTYPE html>

<html>

<head> 

<meta charset="utf-8"> 

<title>Break易站(runoob.com)</title> 

<style type="text/css">

div{

    border: 1px solid #FF0000;

}

</style>

<script>

function changeMargin(){

    document.getElementById("ex1").style.marginBottom="100px";

}

function changePadding(){

    document.getElementById("ex2").style.paddingBottom="100px";

}

</script>

</head>

<body>


<div id="ex1">這是一些文字。</div>

<br>

<button type="button" onclick="changeMargin()">修改div元素的底部外間距</button>

<br>

<br>

<div id="ex2">這是一些文字。</div>

<br>

<button type="button" onclick="changePadding()">修改div元素的底部內間距</button>


</body>

</html>

Style 物件

]
  •   本文標題:HTML DOM Style marginBottom 屬性 - Break易站轉載請保留頁面地址:https://www.breakyizhan.com/html/22354.html