目录

position

描述 (Description)

position属性用于定位元素。 它可以与top,right,bottom和left属性结合使用,将元素定位在您想要的位置。

可能的值 (Possible Values)

  • static - 元素框作为普通文档流的一部分布局,跟随前面的元素和前面的元素。

  • relative - 元素的框被布置为正常流的一部分,然后偏移一段距离。

  • absolute - 元素的框相对于其包含块进行布局,并且完全从文档的正常流中移除。

  • fixed - element.s框绝对定位,具有为position:absolute描述的所有行为。 主要区别在于固定位置元素的包含块始终是视口。

DOM语法 (DOM Syntax)

object.style.position = "static";

适用于 (Applies to)

所有HTML元素。

例子 (Example)

这是一个例子 -

<html>
   <head>
      <style type = "text/css">
         img#lead {position: absolute;}
         div.top {position: fixed; top: 0; height: 10% width: 100%;}
         sup {position: relative; bottom: 0.66em;}
      </style>
   </head>
   <body>
      <img src = "/css/images/bullet.gif">
      <div>iowiki.com</div>
      <p>This text contains <sup>superscript</sup> text.</p>
   </body>
</html> 

它会产生以下结果 -

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