HTML DOM marginLeft 属性

定义和用法

marginLeft 属性设置元素的左外边距。

语法:

  1. Object.style.marginLeft=auto|length|%

可能的值:

描述
auto 浏览器设置的左外边距。
length 定义固定的左外边距。默认值是0。
% 定义基于父对象总高度的百分比左外边距。

实例

本例更改了段落的左外边距:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function changeMargin()
  5. {
  6. document.getElementById("p1").style.marginLeft="32px";
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <input type="button" onclick="changeMargin()"
  13. value="Change the left margin of a paragraph" />
  14.  
  15. <p>This is a paragraph</p>
  16. <p id="p1">This is a paragraph</p>
  17. <p>This is a paragraph</p>
  18.  
  19. </body>
  20. </html>