position:sticky吸顶效果

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body style="height: 100vh; overflow: auto">
    <div style="height: 600vh">
      <div style="height: 300px; background-color: bisque">zll</div>
      <div style="height: 200vh; background-color: lightblue">//关键高度
        <div style="height: 100vh; position: sticky; top: 0">asdasd</div>
      </div>
    </div>
  </body>
</html>

这段代码可以看到的效果:感觉中间蓝色部分的div会吸顶(asdasd文字没有跟随滚动条移动),滑动一段距离中间模块才会跟随着滚动条一起滚动

猜你喜欢

转载自blog.csdn.net/weixin_43925630/article/details/141254607