HTML DOM margin屬性使用手冊
本文向大家描述一下HTML DOM margin屬性的用法,Html中margin屬性主要用來設置元素的外邊距,相信本文介紹一定會讓你有所收獲。
HTML DOM margin屬性
定義和用法
margin屬性設置元素的外邊距。
該屬性可使用1到4個值:
如果規定一個值,比如div{margin:50px}-所有的外邊距都是50px
如果規定兩個值,比如div{margin:50px10px}-上下外邊距是50px,左右外邊距是10px。
如果規定三個值,比如div{margin:50px10px20px}-上外邊距是50px,而左右外邊距是10px,下外邊距是20px。
如果規定四個值,比如div{margin:50px10px20px30px}-上外邊距是50px,右外邊距是10px,下外邊距是20px,左外邊距是30px。
語法:
Object.style.margin=margin
可能的值:
實例
下面的例子改變了段落的外邊距:
- <html>
- <head>
- <scripttypescripttype="text/javascript">
- functionchangeMargin()
- {
- document.getElementById("p1").style.margin="100px";
- }
- < span>script>
- < span>head>
- <body>
- <inputtypeinputtype="button"onclick="changeMargin()"
- value="Changemarginsofaparagraph"/>
- <pidpid="p1">Thisisaparagraph< span>p>
- < span>body>
- < span>html>
【編輯推薦】