How to Remove Blur Effect on Child Elements
When applying a blur filter to a parent element, it can sometimes affect its child elements as well. To prevent this undesired effect, a clever solution involves creating an additional div within the parent element.
Solution:
Create an Overlay Div:
Nest a div within the parent element with a background image that matches the blur effect. Assign it a lower z-index than the parent div.
<code class="html"><div class="content"> <div class="overlay"></div> <div class="opacity">...</div> </div></code>
Apply Blur Effect to Overlay Div:
Apply the blur effect to the overlay div instead of the parent div using CSS:
<code class="css">.content .overlay { background-image: url('...'); -webkit-filter: blur(3px); -moz-filter: blur(3px); -o-filter: blur(3px); -ms-filter: blur(3px); filter: blur(3px); z-index: 0; }</code>
Position Opacity Div in Front:
The opacity div should be positioned in front of the overlay div with a higher z-index.
<code class="css">.opacity { z-index: 10; }</code>
Benefits of This Approach:
The above is the detailed content of How to Prevent Blur Filters from Affecting Child Elements?. For more information, please follow other related articles on the PHP Chinese website!