• 豌豆资源网
  • 开引网企业服务
  • 服务外包网
  • CSS如何将图像转换为模糊图像?

    在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= "1.jpg" width="500px" 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= "1.jpg" width="500px" alt="filter applied" />  
            <div> 
                    <h1>Hello World</h1> 
                    <h2>Blurred Background Image</h2> 
                </div>
            </center>  
        </body>  
    </html>
    posted @ 2020-05-07 21:58  前端一点红  阅读(539)  评论(0编辑  收藏  举报
  • 乐游资源网
  • 热爱资源网
  • 灵活用工代发薪平台
  • 企服知识
  • 355软件知识