目录

margin

描述 (Description)

margin属性是一个速记属性,用于设置元素所有四边的边距宽度。

可能的值 (Possible Values)

  • length - 任何长度值。

  • percentage - 边距的宽度是相对于元素包含块的宽度计算的。

  • auto - 设置要自动计算的所有四个边距的值。

适用于 (Applies to)

所有HTML元素。

DOM语法 (DOM Syntax)

object.style.margin = "5px"

例子 (Example)

这是一个例子 -

<html>
   <head>
   </head>
   <body>
      <p style = "margin: 15px; border:1px solid black;">
         all four margins will be 15px
      </p>
      <p style = "margin:10px 2%; border:1px solid black;">
         top and bottom margin will be 10px, left and right margin will be 2% 
         of the total width of the document.
      </p>
      <p style = "margin: 10px 2% -10px; border:1px solid black;">
         top margin will be 10px, left and right margin will be 2% of the 
         total width of the document, bottom margin will be -10px
      </p>
      <p style = "margin: 10px 2% -10px auto; border:1px solid black;">
         top margin will be 10px, right margin will be 2% of the total 
         width of the document, bottom margin will be -10px, left margin 
         will be set by the browser
      </p>
   </body>
</html> 

这将产生以下结果 -

新页面打开
↑回到顶部↑
WIKI教程 @2018