position:fixed作用简单介绍

position:fixed作用简单介绍:
position:fixed可以认为是position:absolute的加强版本的。
关于绝对定位可以参阅CSS的绝对定位一章节。
position:fixed具有position:absolute的一切特点,比如脱离文档流,可以使用top、left、bottom和right进行定位。
它自己独有的特点就是能够固定于某一位置,代码实例如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>蚂蚁部落</title>
<style>
*{
  margin:0px;
  padding:0px;
}
body{height:1200px;}
.fixed{
  width:50px;
  height:50px;
  background:green;
  position:fixed;
  left:50px;
  top:200px;
}
.abs{
  width:50px;
  height:50px;
  background:green;
  position:absolute;
  right:50px;
  top:200px;
}
</style>
</head>
<body>
<div class="fixed"></div>
<div class="abs"></div>
</body>
</html>

 原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=17922

更多内容可以参阅:http://www.softwhy.com/divcss/

猜你喜欢

转载自softwhy.iteye.com/blog/2275568