• 首页
  • 电影
  • Js
  • 前端
  • 新旅
  • 奇技
  • 网安
  • 歌单
  • 关于
  • 搜索
  • 夜间模式
    ©2013-2025  成长小破站 Theme by OneBlog
    搜索
    标签
    # css # js # uniapp # ps # chrome # 小程序 # javascript # 布局 # typecho # 激活码
  • 首页>
  • 前端笔记>
  • 正文
  • css中sticky属性

    2018年06月07日 1.5 k 阅读 0 评论 1556 字

    sticky粘性定位
    是css新增属性
    其实就是以往我们做的fixed;当滚动条下拉到一定程度设置容器为fixed;
    用图来演示:


    常见场景:通讯录及头部工具条

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>Document</title>
            <style type="text/css" media="screen">
            html{background:#f5f5f5;}
            body{min-height: 1280px;max-width: 640px;margin:0 auto;background:#fff;}
            *{margin:0;padding:0;}
                .nav{color: #fff;font-size: 24pt;padding:0 10px; position: sticky; top: 0px;height: 50px;background: #067;}
                    p{line-height: 2; }
            </style>
        </head>
        <body>
        <nav class="nav">A</nav>
        <p>Keeps elements positioned as "fixed" or "relative" depending on how it appears in the viewport. As a result the element is "stuck" when necessary while scrolling.</p>
    <nav class="nav" style="background:#0f9">B</nav>
    <p>Keeps elements positioned as "fixed" or "relative" depending on how it appears in the viewport. As a result the element is "stuck" when necessary while scrolling.</p>
    <nav class="nav" style="background:#f90">C</nav>
    <p>Keeps elements positioned as "fixed" or "relative" depending on how it appears in the viewport. As a result the element is "stuck" when necessary while scrolling.</p>
    <nav class="nav" style="background:#09f">D</nav>
    <p>Keeps elements positioned as "fixed" or "relative" depending on how it appears in the viewport. As a result the element is "stuck" when necessary while scrolling.</p>
    </body>
    </html>

    兼容情况

    本文著作权归作者 [ admin ] 享有,未经作者书面授权,禁止转载,封面图片来源于 [ 互联网 ] ,本文仅供个人学习、研究和欣赏使用。如有异议,请联系博主及时处理。
    sticky
    取消回复

    发表留言
    回复

    首页电影Js前端新旅奇技网安歌单关于
    Copyright©2013-2025  All Rights Reserved.  Load:0.032 s
    豫公网安备41050202000235   豫ICP备18019224号-2
    Theme by OneBlog V3.6.4
    夜间模式

    开源不易,请尊重作者版权,保留基本的版权信息。