×

采用CSS的filter实现图像高斯模糊的效果

作者:Terry2019.09.21来源:Web前端之家浏览:8075评论:0
关键词:高斯模糊filter

采用CSS的filter实现图像高斯模糊的效果。在CSS中,可以使用filter属性来模糊处理图像;filter属性用于将图像转换为模糊图像。该属性主要用于设置图像的视觉效果。

语法:

filter: blur()

属性值:

blur():给图像设置高斯模糊,值越大越模糊。如果没有设定值,则默认是0;这个参数可设置css长度值,但不接受百分比值。

示例1:使用filter: blur()来模糊图像

<!DOCTYPE html> 
<html> 
	<head> 
	   	<meta charset="UTF-8">
	   	<style>  
            img {  
                -webkit-filter: blur(4px);  
                filter: blur(4px);  
            }  
            h1 {  
                color:green;  
            }  
        </style>
	</head> 
<body> 
    <center>  
        <img src= "/zb_users/upload/2019/09/201909211569051853369164.jpg" width="300px" alt="filter applied" />  
        </center>  
    </body>  
</html>

示例2:创建背景模糊图像

<!DOCTYPE html> 
<html> 
	<head> 
	   	<meta charset="UTF-8">
	   	<style>  
            img {  
                -webkit-filter: blur(4px);  
                filter: blur(4px);  
                margin-top: 20px;
            }  
            h1 {  
                color:red;  
            }  
            .backgr-text { 
                position: absolute; 
                top: 20%; 
                left: 50%; 
                transform: translate(-50%, -50%); 
                text-align: center; 
            }  
        </style>
	</head> 
<body> 
    <center>  
        <img src= "/zb_users/upload/2019/09/201909211569051853369164.jpg" width="300px" alt="filter applied" />  
        <div class="backgr-text"> 
                <h1>Hello World</h1> 
                <h2>Blurred Background Image</h2> 
            </div>
        </center>  
    </body>  
</html>

预览看下效果吧!

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/gaosuj882309482309.html

网友评论文明上网理性发言 已有0人参与

发表评论: