fixed
元素框的表现类似于将 position 设置为 absolute,不过其包含块是视窗本身。可用于导航
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.pg-header{
position: fixed;
height: 50px;
background-color: yellow;
/*text-align: center;*/
/*width:100%;*/
/*line-height: 50px;*/
top:0;
left:0;
right:0;
}
.pg-body{
height:3000px;
background-color: #dddddd;
margin: 50px;
}
</style>
</head>
<body>
<div class="pg-header">头部</div>
<div class="pg-body">内容</div>
</body>
</html>
position中relative和absolute的常用方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="position: relative;border: solid red 1px;width: 500px;height: 200px;margin: 0 auto ">
<div style="background-color: black;width: 20px;height: 20px;position: absolute;right: 0;bottom: 0;"></div>
</div>
</body>
</html>