HTML DOM marginBottom 属性
JavaScript基础 2022-06-08 14:27:0212小码哥的IT人生shichen
HTML DOM marginBottom 属性
定义和用法
marginBottom 属性设置元素的下外边距。
语法:
Object.style.marginBottom=auto|length|%
可能的值:
值 | 描述 |
---|---|
auto | 浏览器设置的一个下外边距。 |
length | 定义一个固定的下外边距。默认值是 0。 |
% | 定义基于父对象总高度的百分比下外边距。 |
实例
本例改变段落的下外边距:
<html> <head> <script type="text/javascript"> function changeMargin() { document.getElementById("p1").style.marginBottom="32px";
} </script> </head> <body> <input type="button" onclick="changeMargin()" value="Change the bottom margin of a paragraph" /> <p>This is a paragraph</p> <p id="p1">This is a paragraph</p> <p>This is a paragraph</p> </body> </html>
TIY
完整实例【marginBottom - 改变元素的下外边距】:
<html> <head> <script type="text/javascript"> function changeMargin() { document.getElementById("p1").style.marginBottom="32px"; } </script> </head> <body> <input type="button" onclick="changeMargin()" value="Change the bottom margin of a paragraph" /> <p>This is a paragraph</p> <p id="p1">This is a paragraph</p> <p>This is a paragraph</p> </body> </html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html