element表格分页

position的sticky粘性定位

2025-03-09  本文已影响0人  每天进步一点点5454
它会根据用户的滚动位置在“相对定位”和“固定定位”之间切换。

工作原理:

 position: sticky;
 left: 0;

底部定位

测试代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>position: sticky 示例</title>
  <style>
    header {
      background-color: lightblue;
      padding: 10px;
      position: sticky;
      bottom: 0; /* 粘性参考点 */
    }
    article {
      padding: 15px;
      height: 2000px; /* 模拟长内容 */
      background-color: #f9f9f9;
    }
  </style>
</head>
<body>
  <article>
    <p>向下滚动页面,观察导航栏的行为。</p>
  </article>
  <header>我是一个粘性导航栏</header>

</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读