固定定位:
当元素的position属性设置为fixed时,则开启了元素的固定定位:
固定定位也是有一种绝对定位,它的大部分特点和绝对定位一样
不同的是:
固定定位永远都会相对于浏览器窗口进行定位
固定定位会固定在浏览器窗口的某个位置,不会随滚动条滚动
IE6不支持固定定位
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>postion</title>
<style>
.box1{
width: 200px;
height: 200px;
background: red;
}
.box2{
width: 200px;
height: 200px;
background: yellow;
/*开启了fixed定位,相对于浏览器窗口定位,一旦定位就变不了了
(绝对定位的一种,绝对定位的特性基本都满足)
* */
position: fixed;
left:300px;
top:100px;
}
.box3{
width: 400px;
height: 400px;
background: green;
}
.sp{
width: 200px;
height: 200px;
background: cyan;
/*元素性质改变,内联变块*/
position: fixed;
left:500px;
top:0;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<span class="sp">这是一个span</span>
</body>
</html>