position:fixed
块级化后可设置margin 相对于自己的偏移量,与top
left
叠加
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0;
background-color: rgba(0,0,0,.1);
}
.father {
width: 400px;
height: 400px;
margin-left: 100px;
position: relative;
}
.son{
width: 100px;
height: 100px;
position: fixed;
margin-left:300px;
margin-top: 100px;
left: 200px;
}
</style>
</head>
<body>
<div class="father">
<div class="son">box</div>
</div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</body>
</html>