css 利用 background-attachment: fixed 实现视觉差效果

效果如图所示:

       

css代码:

div {
      display: block;
      cursor: pointer;
      width: 100%;
      height: 100vh;
      margin-bottom: 20px;
      background-position: center center;
      background-size: cover;
      background-attachment: fixed;
      color: #fff;
      text-shadow: 2px 2px #666;
    }

    .section1 {
      background-image: url(https://img0.baidu.com/it/u=2021795008,2017612367&fm=26&fmt=auto&gp=0.jpg);
      background-color: #fd7400;
    }

    .section2 {
      background-image: url(https://img2.baidu.com/it/u=1129693069,995917531&fm=26&fmt=auto&gp=0.jpg);
      background-color: #ffe11a;
    }

    .section3 {
      background-image: url(https://img0.baidu.com/it/u=3014974138,3272327208&fm=26&fmt=auto&gp=0.jpg);
      background-color: #bedb39;
    }

    .section4 {
      background-image: url(https://img1.baidu.com/it/u=327506210,840215627&fm=26&fmt=auto&gp=0.jpg);
      background-color: #1f8a70;
      /* 不固定背景图 */
      background-attachment:scroll !important; 
    }

    .section5 {
      background-image: url(https://img1.baidu.com/it/u=2446224251,2010104907&fm=26&fmt=auto&gp=0.jpg);
      background-color: #004358;
    }

html代码:

  <div class="section1">图片来源于百度</div>
  <div class="section2">图片来源于百度</div>
  <div class="section3">图片来源于百度</div>
  <div class="section4">图片来源于百度</div>
  <div class="section5">图片来源于百度</div>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值