css如何实现模糊背景效果


当前第2页 返回上一页

HTML布局:

1

2

3

4

5

<div class="bg">

   <div class="drag">

        <div>like window</div>

   </div>

</div>

css代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

/*背景局部模糊*/

.bg{

    width:100%;

    height:100%;

    background: url("../image/banner/banner.jpg") no-repeat fixed;

    padding:1px;

    box-sizing:border-box;

    z-index:1;

}

.drag{

    margin:100px auto;

    width:200px;

    height:200px;

 

    background: inherit;

 

    position: relative;

}

.drag >div{

    width:100%;

    height: 100%;

    text-align: center;

    line-height:200px;

    position: absolute;

    left:0;

    top:0;

    z-index: 11;

}

.drag:after{

    content: "";

    width:100%;

    height:100%;

    position: absolute;

    left:0;

    top:0;

    background: inherit;

    filter: blur(15px);/*为了模糊更明显,调高模糊度*/

    z-index: 2;

}

效果如下:

c18b62e992be887baebb439494eafa5.png

背景局部清晰

背景局部清晰这个效果说简单也不简单,说难也不难。关键还是要应用好background:inherit属性。这里可不能使用transform让它垂直居中了,大家还是选择flex布局吧。如果这里再使用transform属性的话会让背景也偏移的。这样就没有局部清晰的效果了。

html布局同上。

css代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

/*背景局部清晰*/

.bg{

    width:100%;

    height:100%;

    position: relative;

    background: url("../image/banner/banner.jpg") no-repeat fixed;

    padding:1px;

    box-sizing:border-box;

}

.bg:after{

    content: "";

    width:100%;

    height:100%;

    position: absolute;

    left:0;

    top:0;

    background: inherit;

    filter: blur(3px);

    z-index: 1;

}

.drag{

    position: absolute;

    left:40%;

    top:30%;

    /*transform: translate(-50%,-50%);*/

    width:200px;

    height:200px;

    text-align: center;

 

    background: inherit;

    z-index:11;

 

    box-shadow:  0 0 10px 6px rgba(0,0,0,.5);

}

效果:

b383b7744a7caa89fb4b584489097d8.png

以上就是css如何实现模糊背景效果的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

css怎么选择奇偶行元素

了解一些 提高前端开发效率的 css 属性选择器

css怎么在input中插图片

js怎么替换css样式

css怎么设置上边框

css导航条菜单的实现(附源码)

html5实践-使用css制作时间icon的具体详解(图)

css white-space属性怎么用

html如何选择li的偶数列

css中背景图片怎么设置

更多相关阅读请进入《css》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...