


An 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:
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
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)
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%); }
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*/ }
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*/ }
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*/ }
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*/ }
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*/ }
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*/ }
透明度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*/ }
阴影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*/ }
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('#greenish'); -webkit-filter: url('#greenish'); } .imgB{ filter:url('#bluish'); -webkit-filter: url('#bluish'); }
组合滤镜和动画滤镜(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%); }
(有动态效果,但是截图的缘故,只能看静态的了)
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!

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

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

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

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.

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.

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.

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.

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.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor
