头部导航相关

再移动端,头部是作为一个可定制化的组件,例如一下导航

再一般情况下,我们头部是设置一个颜色,但是如果头部的相邻兄弟原生是一个背景图片,头部需要有一种“透明”的效果,如果把头部背景设置成透明,由于吸顶的效果滚动的时候就不行了,此时需要通过头部设置背景图片,将背景图片“截取”一部分,这部分和相邻的兄弟原生的上部分相同,由于吸顶,头部组件脱离文档流,下面相邻的兄弟元素占据头部所在的位置,此时就可以达到头部背景覆盖下面兄弟元素的一部分的效果,从而达成是看起来是一张“图片”

例如:为滚动前

滚动后

全部代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            padding: 0;
            margin: 0;
        }
        .content{
            width: 100%;
            overflow: auto;
            position: relative;
        }
        .head-main{
            height: 60px;
            width: 100%;
            position: fixed;
            top: 0;
            left: 0;
        }
        .head-content{
            height: 100%;
            width: 100%;
            background: rgb(247, 215, 215);
            background: url(./th.jpg);
            background-repeat: no-repeat;
            text-align: center;
            line-height: 60px;
            
        }
        .content-main{
            height: 235px;
            width: 100%;
            background: url(./th.jpg);
            background-repeat: no-repeat;
            background-size: 100%;
        }
        .list2{
            height: 100px;
            width: 100%;
            background-color: rgb(3, 67, 85);
        }
        .list3{
            height: 100px;
            width: 100%;
            background-color: rgb(218, 46, 233);
        }
        .list4{
            height: 100px;
            width: 100%;
            background-color: rgb(27, 41, 53);
        }
        .list5{
            height: 100px;
            width: 100%;
            background-color: rgb(210, 228, 40);
        }
        .list6{
            height: 100px;
            width: 100%;
            background-color: rgb(30, 53, 58);
        }
        .list7{
            height: 100px;
            width: 100%;
            background-color: rgb(227, 28, 221);
        }
        .list8{
            height: 100px;
            width: 100%;
            background-color: rgb(39, 221, 67);
        }
        .list9{
            height: 100px;
            width: 100%;
            background-color: rgb(203, 158, 21);
        }
        .list10{
            height: 100px;
            width: 100%;
            background-color: rgb(31, 142, 239);
        }
        
    </style>
</head>

<body>
    <div class="content">
        <div class="head-main">
            <div class="head-content">我是头部导航</div>
        </div>
        <div class="content-main"></div>
        <div class="list2"></div>
        <div class="list3"></div>
        <div class="list4"></div>
        <div class="list5"></div>
        <div class="list6"></div>
        <div class="list7"></div>
        <div class="list8"></div>
        <div class="list9"></div>
        <div class="list10"></div>
    </div>
</body>

</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值