How to set blur distance in CSS?

WBOY
Release: 2023-09-01 22:37:02
forward
1365 people have browsed it

How to set blur distance in CSS?

CSS (Cascading Style Sheets) is a powerful tool for designing the visuals of a website. TheBlureffect is one of the many features in CSS that is used to blur any element property usingBlur. To create a soft, dreamy effect or draw attention to a specific element on the page, we can use the blur effect.

grammar

css element { filter : blur (amount) }
Copy after login

The concept of fuzzy distance in CSS

Before discussing the practical aspects of setting fuzzy distance, it is important to understand the concept of fuzzy distance. The amount of blur applied to an element is called the blur distance. The value can be defined in pixels (px), em, or other CSS units.

How to apply blur distance in CSS using the "blur" property

To set the blur distance in CSS, you need to use the blur attribute. The Blur property sets the amount of blur that should be applied to the element. To use the Blur attribute, we first select the element to which we want to apply the blur effect and then set the Blur attribute to the desired value.

For example, to apply a blur effect to an image, we can use the following CSS code -

img { filter : blur(5px) }
Copy after login

Here we have selected the "img" element and applied a 5 pixel blur effect to it.

Example 1

This is a complete code example of the above method.

    

Applying blur distance in CSS using the 'blur' property

My Image
Copy after login

We can apply different fuzzy distances to different elements in the web page. To do this, we can select each element individually and set the "blur" property to the desired value. For example -

h1 { filter : blur(3px) } img { filter : blur(5px) }
Copy after login

Here, we have selected two elements, the first "h1" and the second "img", and applied a blur effect of 3 pixels and 5 pixels accordingly.

Example 2: Apply different blur distances to different elements

    

Applying blur distance in CSS using the 'blur' property

Applied blur distance 2 pixels in CSS using the 'blur' property

My Image
Copy after login

Creating a focus effect with blurred distance in CSS

Creating a focus effect is the most common use of blur effects in CSS. This effect is achieved by applying a blur effect to all elements on the web page except the focused element.

To create a focus effect with blurred distance in CSS, use the "blur" attribute with the ":not" pseudo-class. The ':not' pseudo-class allows the user to select all elements except specific elements. For example -

.blur * { transition: all 0.5s ease-in-out; } .blur:hover *:not(.no-blur) { filter: blur(5px); }
Copy after login

Here, we apply the "blur" attribute to all child elements of the "blur" class when the user hovers over the "blur" class. This effect does not work on elements with class "no-blur" because using the "no" pseudo-class excludes elements with class "no-blur" from the blur effect.

Example 3

This is a complete code example of the above method.

    

Creating a focus effect with blur distance in CSS

Hover over the below content to see the effect

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Copy after login

in conclusion

Setting blur distance in CSS is a simple and effective way to add visual appeal to your web pages. With the following examples, you can easily create blur effects on web pages.

The above is the detailed content of How to set blur distance in CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!