html - 模糊除 div 之外的整个页面

标签 html css blur

我有以下代码。

除了中心的红色 div 之外,我需要将其全部模糊。

我尝试使用 filter:nonefilter:blur(0) 但这不起作用。我如何模糊背景中除红色 div 之外的所有内容?

编辑:我也尝试将它与 z-index 一起使用,但也不起作用。

.container{
  width:100%;
  height:100%;
  min-height:400px;
  position:relative;
  filter: blur(0.5rem);
  z-index:1;
}
.text{
  width:50%;
}
.center{
  width:200px;
  height:200px;
  position:absolute;
  top: 50%;
  left:50%;
  transform:translate(-50%, -50%);
  background:#f00;
  z-index:10;
  filter: blur(0);
  filter: none;
}
<div class="container">
    <div class="title">
      <h1>
        some text
      </h1>
    </div>
    <div class="text">
      <p>
        some text goes here that is blurred. some text goes here that is blurred. some text goes here that is blurred. some text goes here that is blurred...
      </p>
    </div>
    <div class="center"></div>
</div>

最佳答案

你应该使用 not为了这。

如果您使用 .container div:not(.center),您的问题应该得到解决。

.container div:not(.center){
  width:100%;
  height:100%;
  min-height:400px;
  position:relative;
  filter: blur(0.5rem);
  z-index:1;
}
.text{
  width:50%;
}
.center{
  width:200px;
  height:200px;
  position:absolute;
  top: 50%;
  left:50%;
  transform:translate(-50%, -50%);
  background:#f00;
  z-index:10;
  filter: blur(0);
  filter: none;
}
<div class="container">
    <div class="title">
      <h1>
        some text
      </h1>
    </div>
    <div class="text">
      <p>
        some text goes here that is blurred. some text goes here that is blurred. some text goes here that is blurred. some text goes here that is blurred...
      </p>
    </div>
    <div class="center"></div>
</div>

关于html - 模糊除 div 之外的整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60018959/

相关文章:

html - 如何在所有浏览器中加粗选择的第一个选项?

html - 资源解释为图像但使用 MIME 类型 text/html appengine go 传输

css - 下拉在 ie8 和 ie9 中看起来不常见

ios - xCode - UIVisualEffectView 动画

jquery - 使用 jQuery 在 Firefox 和 Internet Explorer 中呈现模糊的文本

javascript - 如何适应不同 bootstrap css 文件之间的变化

javascript - 单击按钮将光标置于搜索表单中

java - 如何用JAVA模糊图像的一部分

css - 使用 CSS 动画从中心显示文本并在末尾保持文本可见

html - 相对于容器的字体大小百分比