css 背景图片虚化

项目中需要实现一个背景图片虚化的需求

这里使用了两个div来实现,主要还是图层的覆盖,第一层使用了filter来虚化,第二层直接盖上

  1. 公共布局(使用less的when进行了条件判断,应该有更好的解决方案)
.layoutImportant(@left:50%,@height:100%,@width:100%,@transform:-50%,@backgroundImg) when(isstring(@backgroundImg)){
    position: absolute;
    background-image: url(@backgroundImg);
    background-size: cover;
    height: @height;
    width:@width;
    left: @left;
    transform: translateX(@transform);
}
.layoutImportant(@left:50%,@height:100%,@width:100%,@transform:-50%,@backgroundImg) when(@backgroundImg=null){
    position: absolute;
    background-image: unset;
    background-size: cover;
    height: @height;
    width:@width;
    left: @left;
    transform: translateX(@transform);
}
  1. 需要虚化的背景图片
.backgroundimg{
        .layoutImportant(@height:80%,@width:87.8%,@backgroundImg:"xxx");
        bottom: 6.8%;
        filter: blur(15px); // 虚化的程度
        z-index: 0; // 层级
    }
  1. 放主要内容的div
.content {
        .layoutImportant(@height:80%,@width:87.8%,@backgroundImg:null);
        bottom: 6.8%;
        z-index: 99; // 层级
        }

tip

在样式调整过程中,遇到不可点击图标的情况是因为图层被覆盖了,添加 z-index属性即可解决

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值