目录

top

描述 (Description)

top属性定义绝对定位元素的顶边与其定位上下文的顶边的偏移量,或相对定位元素将被移位的垂直距离。

可能的值 (Possible Values)

  • length - 距离定位上下文顶部的固定距离。

  • percent - 定义上下文高度的某个百分比,假设已明确设置上下文的高度。 如果没有,那么top的百分比值被视为自动。

  • auto - 默认。 让浏览器计算出最高位置。

适用于 (Applies to)

所有HTML定位元素。

DOM语法 (DOM Syntax)

object.style.top = "2px";

例子 (Example)

以下是显示此属性效果的示例 -

<html>
   <head>
   </head>
   <body>
      <p style = "position:absolute; top:100px;">
         This line will be positioned 100px below from the top edge of this window.
      </p>
   </body>
</html>

它会产生以下结果 -

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