做弹出框,拖动效果都要充分利用css中的position属性。

背景

网页中的元素是一种流媒体,默认情况下一个接一个的展现,如果要改变他们的位置,就需要使用定位属性-----position;

原则:寻找参照物

position:

默认值是static;可以省略,topleftbottomrightz-index都不能用

relative;元素相对于它static时候的定位偏移,而且他static时刻占用的空间还是存在的

参照物:static时的元素位置

absolute:元素脱离文档流。定位是相对于父级对象中存在定位属性的。

参照物:第一个有定位属性(absolute;relative;fixed)的父元素位置;

fixed:

inherit:

<html>
<head>
<style type="text/css">
h2.pos_abs
{
position:absolute;
left:100px;
top:150px
}
</style>
</head>

<body>
<div style="width:200px;height:300px;background-color:blue;position:static;top:30px">
<h2 class="pos_abs">这是带有绝对定位的标题</h2>
</div>
<p>通过绝对定位,元素可以放置到页面上的任何位置。下面的标题距离页面左侧 100px,距离页面顶部 150px。</p>
</body>

</html>