>》>》>》>》

解决position:fiexd相对父元素定位

设置position:fiexd之后

不设置top,bottom,left,right位置样式,

通过margin间接调整

复制代码就是开干

 

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Document</title>
  <style>
    .father {
      width:300px;
      height:300px;
      margin-top: 200px;
      margin-left: 200px;
      background:green;
    }

    .son {
      position:fixed;
      margin-top: 140px;
      width:150px;
      height:150px;
      background:red;
      word-break: break-all;
    }
  </style>
</head>
<body>
  <div class="father">
    <div class="son">
      son
    </div>
  </div>
  <p style="height:10000px"></p>
</body>
</html>

 

posted @ 2020-07-17 16:58  大、锤  阅读(387)  评论(0编辑  收藏  举报