Xin's blog Xin's blog
首页
  • 前端文章

    • HTML
    • CSS
    • JavaScript
    • Vue
    • 组件与插件
    • CSS扩展语言
  • 学习笔记

    • 《JavaScript教程》笔记
    • 《JavaScript高级程序设计》笔记
    • 《ES6 教程》笔记
    • 《Vue》笔记
    • 《TypeScript 从零实现 axios》
    • 《Git》学习笔记
    • TypeScript笔记
    • JS设计模式总结笔记
  • 前端框架面试题汇总
  • 基本面试题
  • 进阶面试题
  • 其它
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 前后端联调
  • mock.js
  • 奇技淫巧
  • 分类
  • 标签
  • 归档
关于
GitHub (opens new window)

Xin

英雄可不能临阵脱逃啊~
首页
  • 前端文章

    • HTML
    • CSS
    • JavaScript
    • Vue
    • 组件与插件
    • CSS扩展语言
  • 学习笔记

    • 《JavaScript教程》笔记
    • 《JavaScript高级程序设计》笔记
    • 《ES6 教程》笔记
    • 《Vue》笔记
    • 《TypeScript 从零实现 axios》
    • 《Git》学习笔记
    • TypeScript笔记
    • JS设计模式总结笔记
  • 前端框架面试题汇总
  • 基本面试题
  • 进阶面试题
  • 其它
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 前后端联调
  • mock.js
  • 奇技淫巧
  • 分类
  • 标签
  • 归档
关于
GitHub (opens new window)
  • HTML

  • CSS

    • 知识点

    • 案例

      • flex布局案例-网格布局
      • flex 布局,让某个子元素靠右对齐
      • transform案例
      • 文字在一行或两行时超出显示省略号
      • CSS智慧阴影
      • css3渐变的使用
      • CSS3模糊的使用
        • 毛玻璃效果
        • 背景模糊局部清晰
      • 扫光特效
      • 「布局技巧」图片未加载前自动撑开元素高度
      • 水平垂直居中的几种方式-案例
      • 如何根据系统主题自动响应CSS深色模式
      • 「css技巧」使用hover和attr()定制悬浮提示
  • JavaScript

  • Vue

  • 组件与插件

  • css扩展语言

  • 学习笔记

  • 前端
  • CSS
  • 案例
ctrlwin
2021-08-20

CSS3模糊的使用

# CSS3模糊的使用

# 毛玻璃效果

<html>
<div class="container-filter">
    <div class="content-filter">
        <div class="text">
            "The only way to get rid of a temptation is to yield to it.
            Resist it, and your soul grows sick with longing for the things
            it has forbidden to itself, with desire for what its monstrous
            laws have made monstrous and unlawful."
        </div>
    </div>
</div>
</html>

<style>   
.container-filter {
    min-height: 100vh;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 10px;
    font: 110%/1.6 Baskerville, Palatina, serif;
    position: relative;
    z-index: 1; 
}

.container-filter, .content-filter::before {
    background: url("/blog/img/139.png") 0 / cover fixed;
}

.content-filter {
    position: relative;
    margin: 0 auto;
    padding: 1em;
    max-width: 17em;
    background: hsla(0, 0%, 100%, .25) border-box;
    overflow: hidden;
    border-radius: .3em;
    box-shadow: 0 0 0 1px hsla(0, 0%, 100%, .3) inset,
        0 .5em 1em rgba(0, 0, 0, 0.6);
    text-shadow: 0 1px 1px hsla(0, 0%, 100%, .3);
}

.content-filter::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: -30px; /*模糊在边缘会减弱,用margin:-30px扩大边距*/
    z-index: -1;
    -webkit-filter: blur(20px);
    filter: blur(20px);
    text-decoration: none;
    /**background: url("139.png") 0 / cover fixed;**/
}
.text{
    margin:15px;
    color:#111;
}
</style>
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
.container-filter {
    min-height: 100vh;
    box-sizing: border-box;
    margin: 0;
    padding-top: calc(50vh - 6em);
    font: 150%/1.6 Baskerville, Palatina, serif;
    position: relative;
    z-index: 1; /*使用z-index确定层级关系,必须确保子元素是在最上层的*/
}

.container-filter,
.content-filter::before {
    background: url("139.png") 0 / cover fixed;
}

.content-filter {
    position: relative;
    margin: 0 auto;
    padding: 1em;
    max-width: 23em;
    background: hsla(0, 0%, 100%, .25) border-box;
    overflow: hidden;
    border-radius: .3em;
    box-shadow: 0 0 0 1px hsla(0, 0%, 100%, .3) inset,
        0 .5em 1em rgba(0, 0, 0, 0.6);
    text-shadow: 0 1px 1px hsla(0, 0%, 100%, .3);
}

.content-filter::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    margin: -30px; /*模糊在边缘会减弱,用margin:-30px扩大边距*/
    z-index: -1;
    -webkit-filter: blur(20px);
    filter: blur(20px);
    text-decoration: none;
}
.text{
    margin:40px;
}
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
40
41
42
43
44
<div class="container">
    <div class="content">
        <div class="text">
            "The only way to get rid of a temptation is to yield to it.
            Resist it, and your soul grows sick with longing for the things
            it has forbidden to itself, with desire for what its monstrous
            laws have made monstrous and unlawful."
        </div>
    </div>
</div>
1
2
3
4
5
6
7
8
9
10

# 背景模糊局部清晰

背景局部清晰效果需要使用background:inherit属性,来继承父元素背景。

简单来说,伪元素after通过inherit属性继承了container的背景,并设置全屏大小和模糊效果;content也继承了container的背景,但是没有设置模糊效果。这样就实现背景局部清晰的效果了。

注意!子元素不能使用transform来定位了,会影响最终效果。

<html>
    <div class="container-filter1">
        <div class="content-filter1">
            <div class="text1">
                something like this...
            </div>
        </div>
    </div>
</html>
<style>
.container-filter1 {
    min-height: 100vh;
    box-sizing: border-box;
    font: 110%/1.6 Baskerville, Palatina, serif;
    position: relative;
    z-index: 1;
    background: url("/blog/img/139.png") 0 / cover fixed;
}

.container-filter1::after{
    content: "";
    width:100%;
    height:100%;
    position: absolute;
    left:0;
    top:0;
    background: inherit;
    filter: blur(3px);
    z-index: 1;
}

.content-filter1{
    position: absolute;
    left:20%;
    top:10%;
    width:200px;
    height:200px;
    text-align: center;
    background: inherit;
    z-index:11;
    box-shadow:  0 0 10px 6px rgba(0,0,0,.5);
}
.text1{
    margin:40px;
    color:#111;
}
</style>
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
40
41
42
43
44
45
46
47
.container {
    min-height: 100vh;
    box-sizing: border-box;
    font: 110%/1.6 Baskerville, Palatina, serif;
    position: relative;
    z-index: 1;
    background: url("139.png") 0 / cover fixed;
}

.container::after{
    content: "";
    width:100%;
    height:100%;
    position: absolute;
    left:0;
    top:0;
    background: inherit;
    filter: blur(3px);
    z-index: 1;
}

.content{
    position: absolute;
    left:40%;
    top:30%;
    width:200px;
    height:200px;
    text-align: center;
    background: inherit;
    z-index:11;
    box-shadow:  0 0 10px 6px rgba(0,0,0,.5);
}
.text{
    margin:40px;
}
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
<div class="container">
    <div class="content">
        <div class="text">
            something like this...
        </div>
    </div>
</div>
1
2
3
4
5
6
7
在GitHub上编辑 (opens new window)
#css
上次更新: 1/20/2022, 11:27:12 AM

← css3渐变的使用 扫光特效→

最近更新
01
createElement函数创建虚拟DOM
05-26
02
clipboard 剪切板属性
05-26
03
vue的权限管理
05-16
更多文章>
Theme by Vdoing | Copyright © 2021-2022 Xin | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×