HTML DOM中的Style marginBottom屬性用於設置或返回元素的底邊距。
用法:
- 它返回元素的底邊距。
object.style.marginBottom
- 用於設置元素的底邊距。
object.style.marginBottom = "length|percentage|auto|initial| inherit"
屬性值:
- length:用於將邊距設置為固定單位。其默認值為0。
例:
<!DOCTYPE html> <html> <head> <title> DOM Style marginBottom Property </title> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b>DOM Style marginBottom Property</b> <div class="container"> <div class="div1">Line One</div> <div class="div2">Line Two</div> <button onclick="setMargin()"> Change marginBottom </button> </div> <!-- Script to set bottom margin --> <script> function setMargin() { elem = document.querySelector('.div1'); elem.style.marginBottom = '50px'; } </script> </body> </html>
輸出:
在單擊按鈕之前:
單擊按鈕後:
- percentage:用於將邊距量指定為相對於包含元素寬度的百分比。
Example:<!DOCTYPE html> <html> <head> <title> DOM Style marginBottom Property </title> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b>DOM Style marginBottom Property</b> <div class="container"> <div class="div1">Line One</div> <div class="div2">Line Two</div> <button onclick="setMargin()"> Change marginBottom </button> </div> <!-- Script to set bottom margin --> <script> function setMargin() { elem = document.querySelector('.div1'); elem.style.marginBottom = '10%'; } </script> </body> </html>
輸出:
在單擊按鈕之前:
單擊按鈕後:
- auto:如果該值設置為“自動”,則瀏覽器會自動為邊距大小計算一個合適的值。
Example:<!DOCTYPE html> <html> <head> <title> DOM Style marginBottom Property </title> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b>DOM Style marginBottom Property</b> <div class="container"> <div class="div1" style="margin-bottom:50px;"> Line One </div> <div class="div2"> Line Two </div> <button onclick="setMargin()"> Change marginBottom </button> </div> <!-- Script to set bottom margin --> <script> function setMargin() { elem = document.querySelector('.div1'); elem.style.marginBottom = 'auto'; } </script> </body> </html>
輸出:
在單擊按鈕之前:
單擊按鈕後:
- initial:這用於將屬性設置為其默認值。
Example:<!DOCTYPE html> <html> <head> <title> DOM Style marginBottom Property </title> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b>DOM Style marginBottom Property</b> <div class="container"> <div class="div1" style="margin-bottom:50px;"> Line One </div> <div class="div2"> Line Two </div> <button onclick="setMargin()"> Change marginBottom </button> </div> <!-- Script to set bottom margin --> <script> function setMargin() { elem = document.querySelector('.div1'); elem.style.marginBottom = 'initial'; } </script> </body> </html>
輸出:
在單擊按鈕之前:
單擊按鈕後:
- inherit:用於從元素的父元素繼承值。
Example:<!DOCTYPE html> <html> <head> <title> DOM Style marginBottom Property </title> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b>DOM Style marginBottom Property</b> <div class="container" style="margin-bottom:50px;"> <div class="div1"> Line One </div> <div class="div2"> Line Two </div> <button onclick="setMargin()"> Change marginBottom </button> </div> <!-- Script to set bottom margin --> <script> function setMargin() { elem = document.querySelector('.div1'); elem.style.marginBottom = 'inherit'; } </script> </body> </html>
輸出:
在單擊按鈕之前:
單擊按鈕後:
支持的瀏覽器:下麵列出了DOM Style marginBottom屬性支持的瀏覽器:
- 穀歌瀏覽器
- IE瀏覽器
- Firefox
- Opera
- Safari
相關用法
- HTML Style top用法及代碼示例
- HTML Style right用法及代碼示例
- HTML Style animationTimingFunction用法及代碼示例
- HTML Style fontStyle用法及代碼示例
- HTML Style textDecorationColor用法及代碼示例
- HTML Style animationFillMode用法及代碼示例
- HTML Style lineHeight用法及代碼示例
- HTML Style visibility用法及代碼示例
- HTML Style pageBreakBefore用法及代碼示例
- HTML Style paddingRight用法及代碼示例
- HTML Style paddingLeft用法及代碼示例
- HTML Style paddingBottom用法及代碼示例
- HTML Style width用法及代碼示例
- HTML Style paddingTop用法及代碼示例
- HTML Style pageBreakInside用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 HTML | DOM Style marginBottom Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。