杂七杂八的css

1. position:fixed

以视口为坐标系进行绝对定位,不会随着页面滑动而发生位移。

2. margin-right:-20px

width增加20px。

3. z-index:-1

置于父元素底层。


现在有个需求,上层div不随页面滑动而滑动,图层发生重叠时候,遮盖住低级图层,只显示最高层的颜色。

这里写图片描述

css:

    body{
        height: 200vh;
    }
    #wrap {
        height: 50vh;
        width: 100vw;
        display: flex;
        flex-direction: column;
    }

    #header {
        display: flex;
        position: fixed;        /* 固定div在视口上方 */
        height: 100px;
        width: 100%;
        top: 0;
        justify-content: space-between;
    }
    #header:after{
        content: '';
        height: 100px;
        position: absolute;
        z-index: -1;           /* 值为负数 置于header下面 */
        background-color: white;
        width: 100%;
    }

    .tag {
        display: flex;
        justify-content: center;
        align-items: center;
        width: calc(25% - 15px);  /* 每个div之间距离为20px */
    }
    #middle:before{
        content: '';
        height: 100px;
        display: block;
    }
    #footer {
        display: flex;
        flex-grow: 9;
        justify-content: center;
        align-items: center;
        background-color: pink;
    }

html:

    <div id="wrap">
        <div id="header">
            <div class="tag" style="background-color: lightcoral;">html</div>
            <div class="tag" style="background-color: lightblue;">css</div>
            <div class="tag" style="background-color: #d4c835;">js</div>
            <div class="tag" style="background-color: lightgoldenrodyellow;">xml</div>
        </div>
        <div id="middle" v-html='rawHtml'></div>
        <div id="footer">{{curId}}</div>
    </div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值