search
HomeWeb Front-endCSS TutorialAn example of adding a frosted glass blur effect to an image using the css3 filter attribute

Record the processing of image blur effects in the project. Requirements: The background image must be passed in through the img tag, and the avatar must be made into a round shape.

Example image:

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

HTML code:

<div class="introBox">
    <!--个人头像-->
    <div class="imgShow">
        <img class="imgBground lazy"  src="/static/imghwm/default1.png"  data-src="resources/images/1.jpg"    alt="">
        <ul class="details">
            <li class="smallImg">
                <img class="roundImg lazy"  src="/static/imghwm/default1.png"  data-src="resources/images/1.jpg"    alt="">
            </li>
            <li><p class="uname">吕良伟</p></li>
            <li><p class="cellPhone">13218888888</p></li>
        </ul>
    </div>
</div>

CSS code:

/*背景图模糊效果*/
.imgBground{
    width:100%;
    height:28vh;
    filter: url(blur.svg#blur); /* FireFox, Chrome, Opera */
    -webkit-filter: blur(5px); /* Chrome, Opera */
    -moz-filter: blur(5px);
    -ms-filter: blur(5px);
    filter: blur(5px);
    filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius=5, MakeShadow=false); /* IE6~IE9 */
}
.details{position:absolute; left:0; right:0; top:8%; margin:auto;}/*调整个人信息的位置*/
.smallImg{width:100px; height:100px; margin:2% auto; overflow:hidden;}
/*把头像处理成圆形*/
.roundImg{display:block;width:100px; height:100px; -webkit-border-radius:50%; -moz-border-radius:50%; border-radius:50%;}

About the CSS3 filter attribute, the manual introduces it like this

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

Brightness

The Brightness filter is used to control the brightness of the image. The accepted value of the parameter is greater than or equal to 0. 0% will output pure black, and 100% will output the original brightness of the image. , when it is greater than 100%, the brightness of the picture can be increased, such as 150%, which means the brightness will be increased by 1.5 times

HTML:

<div id="container">
    <img class="imgA lazy"  src="/static/imghwm/default1.png"  data-src="images/1.jpeg"    alt="">
    <img class="imgB lazy"  src="/static/imghwm/default1.png"  data-src="images/1.jpeg"    alt="">
</div>

CSS:

#container{width:600px; height:800px;}
#container img{width:200px;}
.imgB{
    filter:brightness(150%); /*firefox*/
    -webkit-filter:brightness(150%);/*chrome, safari, opera*/
}

Rendering (supported Chrome, Firefox, Opera, Safari, does not support any version of IE)

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

Contrast

The Contrast filter is used to control the contrast of the image, such as the brightness filter Like the filter, which accepts values ​​greater than or equal to 0, this filter controls the difference between the dark and light parts of the CSS image. Therefore, setting 0% is gray, 100% is the original image, and greater than 100% further improves the contrast of the image

CSS:

.imgA{
    filter:contrast(80%);
    -webkit-filter:contrast(80%);
}
.imgB{
    filter:contrast(150%);
    -webkit-filter:contrast(150%);
}

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

Grayscale

The Grayscale filter is used to control the grayscale of the image. This filter gradually converts all the colors in our image into some shades of gray. Setting 0% has no effect, and 100% will turn it into full gray. No Negative values ​​are allowed

CSS:

.imgA{
    filter:grayscale(30%); /*firefox*/
    -webkit-filter:grayscale(30%);/*chrome, safari, opera*/
}
.imgB{
    filter:grayscale(80%); /*firefox*/
    -webkit-filter:grayscale(80%);/*chrome, safari, opera*/
}

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

Saturate

The Saturate filter controls the color saturation of the image, Setting 0% will completely remove all color from the image, setting 100% will look like the original image, and over 100% will saturate the image, disallowing negative values ​​

CSS:

.imgA{
    filter:saturate(30%); /*firefox*/
    -webkit-filter:saturate(30%);/*chrome, safari, opera*/
}
.imgB{
    filter:saturate(150%); /*firefox*/
    -webkit-filter:saturate(150%);/*chrome, safari, opera*/
}

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

BrownSepia

The Sepia filter is used to control the brown tone of the image, which means to adjust the image to a retro-style old photo effect. Set 0% to the original image. , set 100% to the old photo effect

CSS:

.imgA{
    filter:sepia(50%); /*firefox*/
    -webkit-filter:sepia(50%);/*chrome, safari, opera*/
}
.imgB{
    filter:sepia(100%); /*firefox*/
    -webkit-filter:sepia(100%);/*chrome, safari, opera*/
}

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

Hue-rotate

Hue-rotate filter The mirror applies a hue rotation to all colors in the image. There is no effect when setting 0deg. There is no maximum value. When the value exceeds 360deg, it is equivalent to a cycle. That is to say, the effect of setting the value 90deg and 450deg is the same.

CSS:

.imgA{
    filter:hue-rotate(90deg); /*firefox*/
    -webkit-filter:hue-rotate(90deg);/*chrome, safari, opera*/
}
.imgB{
    filter:hue-rotate(150deg); /*firefox*/
    -webkit-filter:hue-rotate(150deg);/*chrome, safari, opera*/
}

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

Invert Color Invert

The Invert filter inverts all colors. The amount of inversion depends on the set value. There is no inversion when it is set to 0%, and it is set to 100%. When inverting all colors

CSS:

.imgA{
    filter:invert(60%); /*firefox*/
    -webkit-filter:invert(60%);/*chrome, safari, opera*/
}
.imgB{
    filter:invert(90%); /*firefox*/
    -webkit-filter:invert(90%);/*chrome, safari, opera*/
}

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

Blur Blur

The Blur filter is suitable for Gaussian blurred images. The colors are blended together and spread over the edges of the image. The radius parameter passed to this filter determines how many pixels on the screen the blend will advance. The larger the value, the more obvious the blur effect. This filter can accept any length value, except percentage

CSS:

.imgA{
    filter:blur(1px); /*firefox*/
    -webkit-filter:blur(1px);/*chrome, safari, opera*/
}
.imgB{
    filter:blur(0.5em); /*firefox*/
    -webkit-filter:blur(0.5em);/*chrome, safari, opera*/
}

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

透明度Opacity

Opacity滤镜使图像变透明,取值0%时,完全透明;取值100%时,完全不透明。这个滤镜跟已知的opacity属性相似,唯一的区别就是性能,opacity滤镜属性在支持硬件加速的浏览器上性能会更好

CSS:

.imgA{
    filter:opacity(25%); /*firefox*/
    -webkit-filter:opacity(25%);/*chrome, safari, opera*/
}
.imgB{
    filter:opacity(75%); /*firefox*/
    -webkit-filter:opacity(75%);/*chrome, safari, opera*/
}

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

阴影Drop Shadow

Drop Shadow滤镜增加了一个阴影效果,此属性需要X和Y的偏移,以及隐隐的颜色,也可以设置一个模糊半径

CSS:

.imgA{
    filter:drop-shadow(5px 5px 10px #666); /*firefox*/
    -webkit-filter:drop-shadow(5px 5px 10px #666);/*chrome, safari, opera*/
}
.imgB{
    filter:drop-shadow(10px 10px 10px #eee); /*firefox*/
    -webkit-filter:drop-shadow(10px 10px 10px #eee);/*chrome, safari, opera*/
}

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

URL()

虽然我们讨论过的所有的滤镜非常有用,他们其实是通用的滤镜,但是你的项目可能需要更多的效果,如果上面滤镜没有能满足你的要求的,你可以创建自己的SVG滤镜然后使用其id通过url()引用。

HTML:

<div id="container">
    <img class="imgA lazy"  src="/static/imghwm/default1.png"  data-src="images/1.jpeg"    alt="">
    <img class="imgB lazy"  src="/static/imghwm/default1.png"  data-src="images/1.jpeg"    alt="">
</div>
 

    
        
            
            
            
        
    
    
        
            
            
            
        
    

CSS:

.imgA{
    filter: url(&#39;#greenish&#39;);
    -webkit-filter: url(&#39;#greenish&#39;);
}
.imgB{
    filter:url(&#39;#bluish&#39;);
    -webkit-filter: url(&#39;#bluish&#39;);
}

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

组合滤镜和动画滤镜(Combining and Animating Filters)

您也可以组合多个滤镜来获得各种效果。在大多数情况下,滤镜的顺序并没有多大关系。但是如果在灰度滤镜后再加上一个褐色滤镜,还是会显示一个灰度图像。

CSS:

.imgB{
    -webkit-animation: haunted 3s infinite;
    animation: haunted 3s infinite;
}
 
@keyframes haunted {
    0% {
        -webkit-filter: brightness(20%);
        filter: brightness(20%);
    }
    48% {
        -webkit-filter: brightness(20%);
        filter: brightness(20%);
    }
    50% {
        -webkit-filter: sepia(1) contrast(2) brightness(200%);
        filter: sepia(1) contrast(2) brightness(200%);
    }
    60% {
        -webkit-filter: sepia(1) contrast(2) brightness(200%);
        filter: sepia(1) contrast(2) brightness(200%);
    }
    62% {
        -webkit-filter: brightness(20%);
        filter: brightness(20%);
    }
    96% {
        -webkit-filter: brightness(20%);
        filter: brightness(20%);
    }
    96% {
        -webkit-filter: brightness(400%);
        filter: brightness(400%);
    }

css3 filter属性给图片添加毛玻璃模糊效果实例介绍

(有动态效果,但是截图的缘故,只能看静态的了)

The above is the detailed content of An example of adding a frosted glass blur effect to an image using the css3 filter attribute. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Anchor Positioning Just Don't Care About Source OrderAnchor Positioning Just Don't Care About Source OrderApr 29, 2025 am 09:37 AM

The fact that anchor positioning eschews HTML source order is so CSS-y because it's another separation of concerns between content and presentation.

What does margin: 40px 100px 120px 80px signify?What does margin: 40px 100px 120px 80px signify?Apr 28, 2025 pm 05:31 PM

Article discusses CSS margin property, specifically "margin: 40px 100px 120px 80px", its application, and effects on webpage layout.

What are the different CSS border properties?What are the different CSS border properties?Apr 28, 2025 pm 05:30 PM

The article discusses CSS border properties, focusing on customization, best practices, and responsiveness. Main argument: border-radius is most effective for responsive designs.

What are CSS backgrounds, list the properties?What are CSS backgrounds, list the properties?Apr 28, 2025 pm 05:29 PM

The article discusses CSS background properties, their uses in enhancing website design, and common mistakes to avoid. Key focus is on responsive design using background-size.

What are CSS HSL Colors?What are CSS HSL Colors?Apr 28, 2025 pm 05:28 PM

Article discusses CSS HSL colors, their use in web design, and advantages over RGB. Main focus is on enhancing design and accessibility through intuitive color manipulation.

How can we add comments in CSS?How can we add comments in CSS?Apr 28, 2025 pm 05:27 PM

The article discusses the use of comments in CSS, detailing single-line and multi-line comment syntaxes. It argues that comments enhance code readability, maintainability, and collaboration, but may impact website performance if not managed properly.

What are CSS Selectors?What are CSS Selectors?Apr 28, 2025 pm 05:26 PM

The article discusses CSS Selectors, their types, and usage for styling HTML elements. It compares ID and class selectors and addresses performance issues with complex selectors.

Which type of CSS holds the highest priority?Which type of CSS holds the highest priority?Apr 28, 2025 pm 05:25 PM

The article discusses CSS priority, focusing on inline styles having the highest specificity. It explains specificity levels, overriding methods, and debugging tools for managing CSS conflicts.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor