


How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example)
This chapter introduces how to use CSS3 to achieve the Gaussian blur effect of images. CSS3 Filter implements blur processing of image elements. Let everyone understand how to set the blur effect of image elements. Through examples, it introduces the filter to achieve Gaussian blur of images. Three effects. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. What is filter
CSS3 Filter attribute defines the element (usually ) visual effects that provide the ability to blur and change the color of elements. CSS3 Fitler is often used to adjust the rendering, background or border display effects of images.
Browser support:
-webkit-filter is an attribute of css3. Webkit is the first to support these functions, and the effect is very good.
#The number in the table indicates the version number of the first browser that supports this method.
The -webkit- immediately following the number is the prefix of the specified browser.
Note: The non-standard "filter" attribute supported by older versions of Internet Explorer (4.0 to 8.0) has been deprecated. IE8 and lower browsers usually use the css opacity attribute.
Let’s take a look at the filter attribute. The effects currently supported in the specification:
-
grayscale (grayscale): the value is a decimal between 0-1
sepia (brown): The value is a decimal between 0-1
saturate (saturation): The value is num
hue-rotate (hue rotation): the value is angle
invert (invert): the value is a decimal between 0-1
opacity (transparency): the value is a decimal between 0-1
brightness (brightness): the value is a decimal between 0-1
contrast (contrast): the value is num
blur (blur): the value is length (radius)
drop-shadow (shadow)
Filter syntax to achieve blur effect:
filter: blur();
blur() sets Gaussian blur to the image. The "length (radius)" value sets the standard deviation of the Gaussian function, or how many pixels are blended together on the screen, so the larger the value, the blurr it is; if there is no set value, the default is 0; this parameter can set the css length value, but percentage values are not accepted.
2. Three effects of image blur
Original picture:
1.css ordinary picture blur effect (the whole picture is blurred)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>图片模糊</title> <style> .bg { width: 1240px; height: 592px; position: relative; background: url("How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example)") no-repeat fixed; padding: 1px; box-sizing: border-box; z-index: 1; } .bg:after { content: ""; width: 100%; height: 100%; position: absolute; left: 0; top: 0; background: inherit; filter: blur(2px); z-index: 2; } .drag { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 200px; height: 200px; text-align: center; z-index: 11; } </style> </head> <body> <div class="bg"></div> </body> </html>
Effect picture:
2.css partial picture blur effect
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>图片模糊</title> <style> .bg { width: 1240px; height: 592px; background: url("How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example)") no-repeat fixed; padding: 1px; box-sizing: border-box; z-index: 1; } .drag { margin: 100px auto; width: 300px; height: 300px; background: inherit; position: relative; text-align: center; } .drag>div { width: 100%; height: 100%; text-align: center; line-height: 200px; position: absolute; left: 0; top: 0; z-index: 11; } .drag:after { content: ""; width: 100%; height: 100%; position: absolute; left: 0; top: 0; background: inherit; filter: blur(30px);/*为了模糊更明显,调高模糊度*/ z-index: 2; } </style> </head> <body> <div class="bg"> <div class="drag">like window</div> </div> </body> </html>
Rendering:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>图片模糊</title> <style> .bg { width: 1240px; height: 592px; background: url("How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example)") no-repeat fixed; padding: 1px; box-sizing: border-box; z-index: 1; } .bg:after { content: ""; width: 100%; height: 100%; position: absolute; left: 0; top: 0; background: inherit; filter: blur(3px); z-index: 1; } .drag { position: absolute; left: 40%; top: 30%; /*transform: translate(-50%,-50%);*/ width: 200px; height: 200px; text-align: center; background: inherit; z-index: 11; box-shadow: 0 0 10px 6px rgba(0, 0, 0, .5); } </style> </head> <body> <div class="bg"> <div class="drag">like window</div> </div> </body> </html>Rendering:
The above is the detailed content of How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example). For more information, please follow other related articles on the PHP Chinese website!

The React ecosystem offers us a lot of libraries that all are focused on the interaction of drag and drop. We have react-dnd, react-beautiful-dnd,

There have been some wonderfully interconnected things about fast software lately.

I can't say I use background-clip all that often. I'd wager it's hardly ever used in day-to-day CSS work. But I was reminded of it in a post by Stefan Judis,

Animating with requestAnimationFrame should be easy, but if you haven’t read React’s documentation thoroughly then you will probably run into a few things

Perhaps the easiest way to offer that to the user is a link that targets an ID on the element. So like...

Listen, I am no GraphQL expert but I do enjoy working with it. The way it exposes data to me as a front-end developer is pretty cool. It's like a menu of

In this week's roundup, a handy bookmarklet for inspecting typography, using await to tinker with how JavaScript modules import one another, plus Facebook's

I've recently noticed an interesting change on CodePen: on hovering the pens on the homepage, there's a rectangle with rounded corners expanding in the back.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function