css 实现高斯模糊
filter: blur(10px)
10px 是所要模糊的数值,可以自己改动,亲测可用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>filter: blur(10px)高斯模糊</title>
<style>
.box {
/* 设置相对定位 */
position: relative;
width: 100%;
height: 530px;
overflow: hidden;
}
.box>img {
width: 100%;
height: 100%;
/* 设置高斯模糊 */
filter: blur(10px);
overflow: hidden;
}
.box>img:hover {
width: 100%;
height: 100%;
/* 设置高斯模糊 hover效果显示全图片 */
filter: blur(0);
overflow: hidden;
}
</style>
</head>
<body>
<div class="box">
<img
src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp09%2F21031FKU44S6-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1660807397&t=6e4ca6647690409a00b0c6aee39c0473"
class="test-img">
</div>
</body>
</html>
注意:
CSS使用filter: blur(10px);实现高斯模糊效果,周边会出现扩展的白边;
解决方案:
对父元素设置overflow: hidden; 隐藏即可。