磨砂玻璃效果:滤镜:blur()

时间:2018-11-13 14:48:23

标签: html css filter blur

编辑:添加了代码笔链接

我目前正在尝试使用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,但这也没有用。

任何建议都将不胜感激。如果需要更多信息,请询问。

2 个答案:

答案 0 :(得分:0)

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>

答案 1 :(得分:-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>

相关问题