一、语法
position:sticky;
top:10px;
二、粘性布局的特点
1.一浏览器的可视窗口为参照点移动元素(固定定位特点)
2.粘性定位占有原来的位置(相对定位特点)
3.必须添加top,left,right,bottom其中一个才有效
三、Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>粘性定位</title>
<style>
body {
height: 3000px;
}
.nav {
/* 粘性定位 */
position: sticky;
top: 0;
width: 800px;
height: 50px;
background-color: pink;
margin: 100px auto;
}
</style>
</head>
<body>
<div class="nav">我是导航栏</div>
</body>
</html>