search
HomeWeb Front-endCSS TutorialHow 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 How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example) ) 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.

How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example)

#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:

  1. grayscale (grayscale): the value is a decimal between 0-1

  2. sepia (brown): The value is a decimal between 0-1

  3. saturate (saturation): The value is num

  4. hue-rotate (hue rotation): the value is angle

  5. invert (invert): the value is a decimal between 0-1

  6. opacity (transparency): the value is a decimal between 0-1

  7. brightness (brightness): the value is a decimal between 0-1

  8. contrast (contrast): the value is num

  9. blur (blur): the value is length (radius)

  10. 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:

How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example)

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:

How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example)

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:

How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example)

##3.css picture partial clear 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;
			}
			
			.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:


How to achieve Gaussian blur effect of images in css3? CSS3 Filter implementation (code example)

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!

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
C++图像处理实践指南:实现图像特效和滤镜C++图像处理实践指南:实现图像特效和滤镜Nov 27, 2023 am 11:40 AM

在计算机科学和图像处理领域,C++一直是最常用的编程语言之一。图像处理是计算机视觉的重要子领域之一,包括图像分析、处理和识别等方面。本文将介绍C++图像处理中的一些基本概念和技巧,并提供一些实现图像特效和滤镜的示例代码,帮助读者更好地理解和实践C++图像处理。一、C++图像处理基础1.1常用的图像文件格式在图像处理中,我们通常需要用到各种图像文件格式,包括

css3如何实现鼠标点击图片放大css3如何实现鼠标点击图片放大Apr 25, 2022 pm 04:52 PM

实现方法:1、使用“:active”选择器选中鼠标点击图片的状态;2、使用transform属性和scale()函数实现图片放大效果,语法“img:active {transform: scale(x轴放大倍数,y轴放大倍数);}”。

解决“[Vue warn]: Failed to resolve filter”错误的方法解决“[Vue warn]: Failed to resolve filter”错误的方法Aug 19, 2023 pm 03:33 PM

解决“[Vuewarn]:Failedtoresolvefilter”错误的方法在使用Vue进行开发的过程中,我们有时候会遇到一个错误提示:“[Vuewarn]:Failedtoresolvefilter”。这个错误提示通常出现在我们在模板中使用了一个未定义的过滤器的情况下。本文将介绍如何解决这个错误并给出相应的代码示例。当我们在Vue的

css3动画效果有变形吗css3动画效果有变形吗Apr 28, 2022 pm 02:20 PM

css3中的动画效果有变形;可以利用“animation:动画属性 @keyframes ..{..{transform:变形属性}}”实现变形动画效果,animation属性用于设置动画样式,transform属性用于设置变形样式。

另辟蹊径!看看使用CSS滤镜怎么构建圆角和波浪效果另辟蹊径!看看使用CSS滤镜怎么构建圆角和波浪效果Oct 18, 2022 pm 08:21 PM

本篇文章带大家另辟蹊径,聊聊使用CSS滤镜构建圆角的方法,并利用圆角聊聊实现波浪效果的方法,希望对大家有所帮助!

css3怎么设置动画旋转速度css3怎么设置动画旋转速度Apr 28, 2022 pm 04:32 PM

在css3中,可以利用“animation-timing-function”属性设置动画旋转速度,该属性用于指定动画将如何完成一个周期,设置动画的速度曲线,语法为“元素{animation-timing-function:速度属性值;}”。

聊聊怎么使用CSS滤镜实现圆角及波浪效果聊聊怎么使用CSS滤镜实现圆角及波浪效果Jul 28, 2022 pm 07:42 PM

怎么利用CSS实现圆角及波浪效果?下面本篇文章带大家了解一下怎么巧用CSS滤镜构建圆角及波浪效果,希望对大家有所帮助!

css3线性渐变可以实现三角形吗css3线性渐变可以实现三角形吗Apr 25, 2022 pm 02:47 PM

css3线性渐变可以实现三角形;只需创建一个45度的线性渐变,设置渐变色为两种固定颜色,一个是三角形的颜色,另一个为透明色即可,语法“linear-gradient(45deg,颜色值,颜色值 50%,透明色 50%,透明色 100%)”。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

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.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!