【问题标题】:Frosted Glass effect: filter: blur()磨砂玻璃效果:过滤器:模糊()
【发布时间】:2019-04-16 10:32:12
【问题描述】:

编辑:添加 codepen 链接

我目前正在尝试使用 CSS 获得磨砂玻璃效果,但是我尝试的所有方法都只是产生了轻微的色调。

这正在 Chrome 中进行测试。

body {
  font: 15px/1.5 Arial, Helvetica, sans-serif;
  padding: 0;
  margin: 0;
  background: url("https://i.imgur.com/ht1etAo.jpg");
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}

.frost {
  color: #ffffff;
  width: 400px;
  height: 200px;
  position: absolute;
  background: inherit;
  overflow: hidden;
  margin: 0 auto;
  padding: 2rem;
}

.frost:before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: inherit;
  filter: blur(20px);
  box-shadow: inset 0 0 3000px rgba(255, 255, 255, 0.5);
  margin: -20px;
}
<section id="frontImage">
  <div class="container">
    <div class="frost">
      <h3>Testing Glass</h3>
    </div>
  </div>
</section>

filter 属性似乎并没有真正起作用,因为更改它实际上不会影响 div。

这是我的代码:我正在尝试模糊霜 div

针对这种效果:https://codepen.io/AmJustSam/full/ModORY/

我有什么:https://codepen.io/anon/pen/PxWEde

我也尝试过使用 webkit-blur,但也没有用。

非常感谢任何建议。如果需要更多信息,请询问。

【问题讨论】:

  • 你能提供一个 jsfiddle/codepen 或类似的东西来代替截图吗?另外我不太明白你想要的结果是什么,你能详细说明一下吗?
  • 您不想将过滤器应用于正文(具有背景图像)吗?
  • 目前您正在将过滤器应用于前元素,这只是模糊了盒子阴影。您究竟想模糊什么,背景图像或“测试玻璃”元素?
  • 我想模糊框后面的背景我添加了代码笔以显示所需的结果

标签: html css filter blur


【解决方案1】:

body {
  padding: 0;
  margin: 0;
  background: url("https://i.imgur.com/ht1etAo.jpg");
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  display: flex;
  justify-content: center;
}

.frost {
  width: 400px;
  height: 200px;
  position: absolute;
  background: inherit;
}

.frost:before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  filter: blur(2px);
  background: inherit;
}

.content {
  position: absolute;
  width: 340px;
  height: 140px;
  top: 30px;
  left: 30px;
}
<div class="frost">
  <div class="content">
    <h3>Testing Glass</h3>
    <p>lipsum</p>
  </div>
</div>

【讨论】:

  • 我希望文本保持未经过滤,我解释了我想要的不好。我已经将一个 codepen 链接到一个编码器 (AmJustSam),他有一个我想要获得的效果的例子
  • 你不能直接从 codepen 复制确切的效果吗?我已对以上内容进行了编辑,以更好地反映匹配链接效果所需的设置。
  • 恐怕不行,我试过了,实际上什么都没有显示
【解决方案2】:

我认为使用原始图像的模糊版本获得逼真的玻璃效果的最佳方法。

Ps:别担心,伙计们遇到了 HTML 小部件的问题。

这是代码希望对你有帮助

html,
body {
  padding: 0;
  margin: 0;
}
h2 {
text-align:center;
color:white;
}
.glass-effect--bg-inner {
position:relative;
z-index:1;
padding-top:20px;
}
.container {
  width: 100%;
  height: 100%;
  min-height: 500px;
}

.large-hero--bg {
  background: url(https://cdn-std.dprcdn.net/files/acc_609131/p6BW2C) no-repeat fixed;
  background-size: cover;
  background-position: 50% 0;
}


.glass-effect {
  position: relative;
  height: 250px;

}

.glass-effect--bg:after {
   
      position: absolute;
      top: 0;
      left: 0;
      z-index: 0;
      width: 100%;
      height: 100%;
      background: url("https://cdn-std.dprcdn.net/files/acc_609131/EElxHZ") repeat fixed;
      background-size: cover;
      background-position: 50% 0;
      content: "";
      filter: url("https://cdn-std.dprcdn.net/files/acc_609131/EElxHZ") repeat fixed;
      -webkit-filter: blur(5px);
      filter: blur(5px);
  
  }
<div class="container large-hero--bg ">
  <div class="glass-effect glass-effect--bg">
<div class="glass-effect--bg-inner">

  <h2>Lorem ispsum dolor</h2>
  </div>
  </div>
</div>

【讨论】:

  • 虽然这在理论上可以回答问题,it would be preferable 在此处包含答案的基本部分,并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效
  • 谢谢!这更符合我想要的。我现在遇到的唯一问题是它不显示文本,并且在调整窗口大小时,它与窗口背景不对齐。编辑:修复了 z-index 的文本问题
  • 您应该能够将所需的任何元素添加到玻璃效果容器中。让我知道这是否有效。
猜你喜欢
  • 2012-07-21
  • 2021-11-12
  • 2014-05-02
  • 1970-01-01
  • 2017-05-18
  • 1970-01-01
  • 1970-01-01
  • 2020-02-03
  • 1970-01-01
相关资源
最近更新 更多