一:相对定位 relative

relative生成相对正常位置进行定位;例如“left:20”会向left位置添加20像素;

     注意:margin-left属性不能使用。

h2.pos_right
{
position:relative;
left:200px
}/*相对正常位置向右移动200像素*/

二:绝对定位 absolute

 absolute 生成绝对元素,相对于默认值定位以外的第一个父元素进行定位

注意:通过绝对定位,元素可以放置在界面任何位置

 h2.pos_abs
{
position:absolute;
left:100px;
top:150px
}/*相对父元素*/

三:固定位置fixed

fixed相对浏览器窗口对元素进行定位。

 p.two
{
position:fixed;
top:30px;
right:5px;
}

四:设置元素形状

<html>
<head>
<style type="text/css">
img 
{
position:absolute;
clip:rect(0px 50px 200px 0px)
}
</style>
</head>
<body>
<p>clip 属性剪切了一幅图像:</p>
<p><img border="0" src="/i/eg_bookasp.gif" width="120" height="151"></p>
</body>
</html>

 

posted on 2015-12-01 20:11  ich  阅读(157)  评论(0编辑  收藏  举报