html - 使用 CSS 创建模糊纯色背景

标签 html css

我需要帮助才能使用 css 将光泽模糊效果应用于纯色背景:

<div class="container">
  <div class="overlay">
    Hello World!
  </div>
</div>
.container {
  background: blue;
  width: 100%;
  height: 300px;
}

.overlay {
  color: #FFF;
  padding: 20px;
}

JSFiddle:https://jsfiddle.net/znp73yr6/

最佳答案

使用下面的代码片段,使用 filter: blur(5px); 实现模糊效果

.container {
    position: relative;
    width: 100%;
    height: 300px;
}

.blur {
    background: blue url(http://i.stack.imgur.com/fAcHL.jpg);
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-filter: blur(5px);
    -moz-filter: blur(5px);
    -o-filter: blur(5px);
    -ms-filter: blur(5px);
    filter: blur(5px);
    z-index: 1;
}

.overlay {
    color: #FFF;
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 2;
}
<div class="container">
    <div class="blur"></div>
    <div class="overlay">
      Hello World!
    </div>
</div>

关于html - 使用 CSS 创建模糊纯色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37910791/

相关文章:

javascript - 将 document.getElementById 存储在变量中?

javascript - 输入类型=密码值返回空,除非我在 chrome 控制台中使用断点

javascript - 4 幅图像的响应式网格

css - 有没有办法设计最后一行文字的字体颜色?

javascript - 使用javascript创建文本文件

html - Img 在导航中间

html - 如何合并最后一列中的 5 行?

html - CSS 替换 YouTube 嵌入的黑条

html - 透明、无边框的文本输入

css - 在 div 内部拉伸(stretch) div 并填充空的 div 空间