【问题标题】:How to create a semi-transparent blurry overlay?如何创建半透明模糊叠加?
【发布时间】:2019-02-27 13:51:33
【问题描述】:

我有两个 div。其中div1 具有背景颜色和图像图案,而div2 具有透明背景颜色,我希望div2 背景模糊,但不是其内容。

我研究了很多,但找不到类似的例子。

.container {
  width: 400px;
  height: 300px;
  background-color: #3d3d3d;
  position: relative;
  background-image: url('https://i.stack.imgur.com/Kpp7i.png');
  background-repeat: repeat;
  background-size: 50%;
}

.chat {
  color: green;
  line-height: 28px;
}

.type {
  width: 100%;
  height: 100px;
  position: absolute;
  left: 0;
  bottom: 0;
  background-color: rgba(45, 45, 45, 0.45);
  color: rgba(255, 255, 255, 0.8);
  padding: 10px;
  box-sizing: border-box;
  line-height: 20px;
}
<div class="container">
  <div class="chat">
    Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
    one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
    et Malorum" (The Extremes of Good and
  </div>
  <div class="type">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry'unchanged.
  </div>
</div>

类似这样的:

【问题讨论】:

  • 有很多类似的问题,通常归结为 css backdrop-filter (目前还没有太多支持,可能会或可能不会出现在规范中)或CSS filter: blur() 您需要使用一些布局技巧来呈现模糊背景的外观。
  • 就像@DBS 所说,最好的方法是使用 webkit 和背景过滤器,它在不同浏览器中的支持非常少,一个好的解决方法是使用这里的答案stackoverflow.com/a/38543010/8952861。但看到你的文字也存在于不会被模糊的元素中

标签: html css


【解决方案1】:

有很多文章涵盖了这一点,这里有一篇应该有用:

How can I make a CSS glass/blur effect work for an overlay?

  1. 设置您的图像。
  2. 创建一个放置在上面的 div,这就是你的叠加层。
  3. 使用 rgba(a 设置不透明度),如下所示: background: rgba(34,34,34,0.75);

参考文献:

  1. https://jordanhollinger.com/2014/01/29/css-gaussian-blur-behind-a-translucent-box/
  2. How can I make a CSS glass/blur effect work for an overlay?

【讨论】:

  • 参考他底部的图片链接,他/她不希望整个背景只模糊文本的div部分
  • 好电话!刚刚替换了我的答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-04-21
  • 1970-01-01
  • 2014-08-07
  • 1970-01-01
  • 2021-06-24
  • 2016-11-18
  • 1970-01-01
相关资源
最近更新 更多