當(dāng)元素的position屬性設(shè)置fixed時(shí),則開(kāi)啟固定定位
固定定位也是一種絕對(duì)定位,它的大部分特點(diǎn)都和絕對(duì)定位一樣
不同的是:
- 固定定位永遠(yuǎn)都會(huì)相對(duì)于瀏覽器窗口進(jìn)行定位
- 固定定位會(huì)固定在瀏覽器窗口某個(gè)位置,不會(huì)隨滾動(dòng)條滾動(dòng)
- IE6不支持固定定位
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.box1{
width: 200px;
height: 200px;
background-color: red;
}
.box2{
width: 200px;
height: 200px;
background-color: yellow;
position: fixed;
left: 0px;
top: 0px;
}
.box3{
width: 200px;
height: 200px;
background-color: yellowgreen;
}
.box4{
width: 300px;
height: 300px;
background-color: orange;
position: relative;
}
</style>
</head>
<body style="height: 5000px;">
<div class="box1"></div>
<div class="box4">
<div class="box2"></div>
</div>
<div class="box3"></div>
</body>
</html>
預(yù)覽:

2020-02-19 20.39.21.gif