How to Prevent Child Elements from Inheriting Blur Effects in CSS?

Linda Hamilton
Release: 2024-10-25 11:52:02
Original
188 people have browsed it

How to Prevent Child Elements from Inheriting Blur Effects in CSS?

Removing Blur Effect on Child Elements with CSS

When using CSS blur effects on a parent element, it's common to encounter the issue of child elements also inheriting the blur. To resolve this, we can create a separate div within the parent and apply the blur effect to it instead.

Implementation

  1. Add an additional div within the content div and assign it a class, such as overlay.
<code class="html"><div class="content">
  <div class="overlay"></div>
  <div class="opacity">
    <!-- Child elements... -->
  </div>
</div></code>
Copy after login
  1. In CSS, assign the blur effect and background image to the overlay div, ensuring that its z-index is lower than the opacity div:
<code class="css">.content {
  float: left;
  width: 100%;
}

.content .overlay {
  background-image: url('images/zwemmen.png');
  height: 501px;
  -webkit-filter: blur(3px);
  -moz-filter: blur(3px);
  -o-filter: blur(3px);
  -ms-filter: blur(3px);
  filter: blur(3px);
  z-index: 0;
}

.opacity {
  background-color: rgba(5, 98, 127, 0.9);
  height: 100%;
  overflow: hidden;
  position: relative;
  z-index: 10;
}</code>
Copy after login

By giving the overlay div a lower z-index, the child elements within the opacity div will be positioned above it, ensuring that they are not affected by the blur effect.

The above is the detailed content of How to Prevent Child Elements from Inheriting Blur Effects in CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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 Articles by Author
Popular Tutorials
More>
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!