目录

margin-top

描述 (Description)

margin-top属性设置元素顶部边距的宽度。

可能的值 (Possible Values)

  • length - 任何长度值。

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

  • auto - 默认,让浏览器自动设置边距。

适用于 (Applies to)

所有HTML元素。

DOM语法 (DOM Syntax)

object.style.marginTop = "5px"

例子 (Example)

这是一个例子 -

<html>
   <head>
   </head>
   <body>
      <p style = "margin-top: 15px; border:1px solid black;">
         This is a paragraph with a specified top margin
      </p>
      <p style = "margin-top: 5%; border:1px solid black;">
         This is another paragraph with a specified top margin in percent
      </p>
   </body>
</html>

这将产生以下结果 -

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