Home  >  Article  >  Web Front-end  >  Use css filter:blur to achieve the blur effect of images (code example)

Use css filter:blur to achieve the blur effect of images (code example)

不言
不言Original
2018-11-07 14:22:554367browse

The content of this article is about using CSS filters to achieve the blur effect of images. Friends in need can refer to it. Without further ado, let’s take a look at the main text.

I recently encountered the problem of filter:blur in css. First, let us take a look at an image on the page, as shown below:

HTML:

<div class="imageContainer">
<img  src="image/1.jpg" alt="Use css filter:blur to achieve the blur effect of images (code example)" >
</div>

CSS:

.imageContainer {
    border: solid 5px black;
    width: 1024px;
    height: 768px;
    }

Use css filter:blur to achieve the blur effect of images (code example)

Now, let’s apply a nice blur effect:

img {
-webkit-filter: blur(30px);
}

The effect is as follows:

Use css filter:blur to achieve the blur effect of images (code example)

Observed that the image is blurred beyond the borders of its container and a "glow" effect appears between the blurred image and the black border, now let's fix this issue.

Solution:

.imageContainer {
overflow: hidden;
}    
img {
+transform:scale(1.1);
}

The effect is as follows:

Use css filter:blur to achieve the blur effect of images (code example)


The above is the detailed content of Use css filter:blur to achieve the blur effect of images (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