取消模糊背景中的内容 div

Unblur content inside blurring background div

所以我真的很喜欢这里的这种特殊效果 https://www.w3schools.com/howto/howto_css_blurred_background.asp,您可以在其中模糊背景并显示文字。我现在遇到的问题是我想在我的第一个内容下方为我的第二个内容添加另一个墙纸。第一个内容不错。现在我希望我的第二个内容在您滚动时出现在第二个墙纸中。有点像创建视差效果,但我正在创建自己独特的网站。

这次我想要一个模糊的背景(第二张壁纸),同时让我想要的东西放在它的位置并让它聚焦。

有办法实现吗?

bg-image2 开始,我希望 h1pbg-image2 内聚焦在模糊的背景图像上。

注意: 墙纸不会显示在下面的片段中,因为我已经得到了我需要的图片我的文件夹位于我的电脑中。

body,
html {
  height: 100%;
}

* {
  box-sizing: border-box;
}

.bg-image {
  /* The image used */
  background-image: url("images/wallpaper1.jpg");
  /* Add the blur effect */
  filter: blur(8px);
  -webkit-filter: blur(8px);
  /* Full height */
  height: 100%;
  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}


/* Position text in the middle of the page/image */

.bg-text {
  background-color: rgb(0, 0, 0);
  /* Fallback color */
  background-color: rgba(0, 0, 0, 0.4);
  /* Black w/opacity/see-through */
  color: white;
  font-weight: bold;
  border: 3px solid #f1f1f1;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 80%;
  padding: 20px;
  text-align: center;
}

.bg-image2 {
  /* The image used */
  background-image: url("images/wallpaper2.jpg");
  /* Add the blur effect */
  filter: blur(8px);
  -webkit-filter: blur(8px);
  /* Full height */
  height: 100%;
  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.profilePicture {
  position: absolute;
  left: 50%;
  margin: 200px auto;
  transform: translate(-50%, -50%);
}
<div class="bg-image"></div>

<div class="bg-text">
  <h1>My name is Whosebug</h1>
  <p>And I am a website</p>
</div>


<div class="bg-image2">

  <!-- This is the part where I want my stuff to not be blurred and focus -->
    
  <div class="profilePicture">
    <img src="images/profilePic.jpg" style="width: 170px; height: 170px; border-radius:50%;">
    <h1>This is a title</h1>
    <p>This is just a paragraph</p>
  </div>

</div>

这就是您想要的结果吗?

https://codepen.io/anon/pen/exVRyy

我所做的就是在 bg-image2profilePicture 周围创建一个 div,这样 bg-image2 上的模糊就不会影响 profilePicture ,然后将 div 设置为 position:relative; ,这样 profilePicture 就可以像您一样放在中间。

这是您编辑的 HTML:

<div class="bg-image"></div>

<div class="bg-text">
    <h1>My name is Whosebug</h1>
    <p>And I am a website</p>
</div>

<div class="bg-test">
  <div class="bg-image2">

    <!-- This is the part where I want my stuff to not be blurred and focus -->

  </div>

  <div class="profilePicture">
      <img src="https://images.pexels.com/photos/1253661/pexels-photo-1253661.jpeg?cs=srgb&dl=android-wallpaper-bluhen-blume-1253661.jpg&fm=jpg" style="width: 170px; height: 170px; border-radius:50%;">
      <h1>This is a title</h1>
      <p>This is just a paragraph</p>
    </div>
</div>

和 CSS:

body,
html {
  height: 100%;
}

* {
  box-sizing: border-box;
}

.bg-image {
  /* The image used */
  background-image: url("https://images.unsplash.com/photo-1507608616759-54f48f0af0ee?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80");
  /* Add the blur effect */
  filter: blur(8px);
  -webkit-filter: blur(8px);
  /* Full height */
  height: 100%;
  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}


/* Position text in the middle of the page/image */

.bg-test {
  position:relative;
}

.bg-text {
  background-color: rgb(0, 0, 0);
  /* Fallback color */
  background-color: rgba(0, 0, 0, 0.4);
  /* Black w/opacity/see-through */
  color: white;
  font-weight: bold;
  border: 3px solid #f1f1f1;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  width: 80%;
  padding: 20px;
  text-align: center;
}

.bg-image2 {
  /* The image used */
  background-image: url("https://whatthenewsblog.files.wordpress.com/2015/03/ecl-ann.jpg");
  /* Add the blur effect */
  filter: blur(8px);
  -webkit-filter: blur(8px);
  /* Full height */
  height: 100vh;
  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.profilePicture {
  position: absolute;
  left: 50%;
  top:50%;
  margin: 0 auto;
  transform: translate(-50%, -50%);
}

我遇到了类似的问题。经过大量搜索,我找到了完美的解决方案。 您可以使用 backdrop-filter.

您的代码:

body,
    html {


      height: 100%;
    }
    
    * {
        padding: 0px;
        margin: 0px;
      box-sizing: border-box;
    }
    
    .bg-image {
      /* The image used */
      background-image: url("https://images.unsplash.com/photo-1507608616759-54f48f0af0ee?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80");
      /* Add the blur effect */
      
      /* Full height */
      height: 100%;
      /* Center and scale the image nicely */
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
    }
    
    
    /* Position text in the middle of the page/image */
    
    .bg-test {
      position:relative;
    }
    
    .bg-text {
      background-color: rgb(0, 0, 0);
      /* Fallback color */
      background-color: rgba(0, 0, 0, 0.4);
      /* Black w/opacity/see-through */
      color: white;
      font-weight: bold;
      backdrop-filter: blur(8px);
      border: 3px solid #f1f1f1;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      z-index: 2;
      width: 80%;
      padding: 20px;
      text-align: center;
    }
    
    .bg-image2 {
      /* The image used */
      background-image: url("https://blog.prezi.com/wp-content/uploads/2019/03/patrick-tomasso-208114-unsplash-1024x768.jpg");
      /* Add the blur effect */
      /* Full height */
      height: 100vh;
      /* Center and scale the image nicely */
      background-position: center;
      background-repeat: no-repeat;
      background-size: cover;
    }
    
    .profilePicture {
      backdrop-filter: blur(8px);
      height: 100vh;
      width: 100vw;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      position: absolute;
      left: 50%;
      color: white;
      top:50%;
      margin: 0 auto;
      transform: translate(-50%, -50%);
    }
<div class="bg-image">

<div class="bg-text">
    <h1>My name is Whosebug</h1>
    <p>And I am a website</p>
</div>
</div>

<div class="bg-test">
  <div class="bg-image2">

    <!-- This is the part where I want my stuff to not be blurred and focus -->
    <div class="profilePicture">
      <img src="https://images.pexels.com/photos/1253661/pexels-photo-1253661.jpeg?cs=srgb&dl=android-wallpaper-bluhen-blume-1253661.jpg&fm=jpg" style="width: 170px; height: 170px; border-radius:50%;">
      <h1>This is a title</h1>
      <p>This is just a paragraph</p>
    </div>
  </div>
  
  
</div>

我知道你问了这么久,你得到了答案。 希望这对其他人有帮助:)

我修改了 cryptomothy

的代码