css3滤镜开发模糊背景效果(99)
程序员文章站
2022-06-26 08:40:14
先来个简单的小例子:图片模糊处理:filter:blur(13px):数值越大越模糊。负值和零都是正常不模糊情况下。
一:背景全部模糊效果,中间文字部分不模糊
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style>
.box {
position: relative;
height: 600px;
margin: 0px auto;
background: url(images/1.jpg) no-repeat center;
background-size: 100% 100%;
z-index: 1;
}
.box::after{
content: "";
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
background: inherit ;
background-size: 100% 100%;
filter: blur(11px);
z-index: 2;
}
p{
width: 100%;
position: absolute;
top:50%;
text-align: center;
font-size: 36px;
color:rgb(8, 8, 8);
z-index: 3;
}
</style>
</head>
<body>
<div class="box">
<p>总有一些人在等你,沿途风景很美好<br>
别忘了有人在此等你!
</p>
</div>
</body>
</html>
二:如何局部模糊呢?让层级高的盒子在上面变模糊和变小一点,根据自己的需要来进行设置大小:
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style>
.box {
position: relative;
height: 600px;
margin: 0px auto;
background: url(images/1.jpg) no-repeat center;
background-size: 100% 100%;
z-index: 1;
}
.box::after{
content: "";
width: 300px;
height: 300px;
position: absolute;
top:50%;
left: 50%;
margin-left: -150px;
margin-top: -150px;
background: inherit ;
background-size: 100% 100%;
filter: blur(11px);
z-index: 2;
}
p{
width: 100%;
position: absolute;
top:50%;
text-align: center;
font-size: 36px;
color:rgb(8, 8, 8);
z-index: 3;
}
</style>
</head>
<body>
<div class="box">
<p>总有一些人在等你,沿途风景很美好<br>
别忘了有人在此等你!
</p>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style>
.box {
height: 600px;
margin: 0px auto;
z-index: 1;
}
.bg {
position: relative;
height: 600px;
margin: 0px auto;
background: url(images/1.jpg) no-repeat center;
background-size: 100% 100%;
filter: blur(11px);
z-index: 2;
}
.box::after {
content: "";
width: 300px;
height: 300px;
position: absolute;
top: 50%;
left: 50%;
margin-left: -150px;
margin-top: -150px;
background: url(images/1.jpg) no-repeat center;
background-size: 100% 100%;
filter: blur(0px);
z-index: 3;
}
</style>
</head>
<body>
<div class="box">
<div class="bg">
总有一些人在等你,沿途风景很美好<br>
别忘了有人在此等你!
</div>
</div>
</body>
</html>
本文地址:https://blog.csdn.net/weixin_45147894/article/details/107151048
上一篇: 设计模式-策略模式
下一篇: Visual Studio Code配置