首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >css中sticky属性

css中sticky属性

作者头像
发布2021-11-08 10:13:06
发布2021-11-08 10:13:06
9550
举报
文章被收录于专栏:IT杂症IT杂症

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

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

代码语言:javascript
复制
<!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>

兼容情况

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018年06月07日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档