Achieving Defined Edges with CSS3 Filter Blur
When applying a blur effect to an image using the CSS filter property, a common issue arises: the edges of the image also become blurred. This can result in an undesirable outcome, particularly when sharp lines or details need to be preserved.
To resolve this problem and maintain defined edges, a clever technique can be employed. By placing the blurred image within a
The following code snippet demonstrates how to achieve this effect:
img { filter: blur(5px); -webkit-filter: blur(5px); -moz-filter: blur(5px); -o-filter: blur(5px); -ms-filter: blur(5px); margin: -5px -10px -10px -5px; } div { overflow: hidden; }
In this code, the element is contained within a
Furthermore, negative margins are applied to the element to slightly shift it within the
This technique effectively creates a defined blur effect, keeping the edges of the image sharp while softening the details within.
The above is the detailed content of How Can I Achieve a Defined Blur Effect in CSS3 While Preserving Sharp Edges?. For more information, please follow other related articles on the PHP Chinese website!