一:背景全部模糊效果,中間文字部分不模糊
代碼如下:
<!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>