如何在 Boostrap 中的背景图像上应用模糊效果



我正在尝试在具有全屏背景图像的页面第一行应用简单的模糊效果。

问题是,我在背景图像的边框上看到了不应该存在的阴影,最重要的是,位于背景图像顶部的徽标也被模糊了。

我知道我正在模糊introdiv,这反过来又模糊了其中的所有内容,所以我也必须错误地应用背景图像。

实现这一目标的最佳方法是什么?

谢谢。

<div class="intro">
<div class="container-fluid">
<div class="row">
<div class="col-md-12 text-center">
<img src="assets/img/logo.png" alt="Logo" class="logo">
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<h1>Another row</h1>
</div>
</div>

这是 CSS

html, body {
width: 100%;
height: 100%;
}
body {
background-color: #191617;
}
.logo {
width: 220px;
margin-top: 10em;
}
.intro {
background: url('../img/bg/bg2.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 100%;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
}

演示 https://jsfiddle.net/0334yL41/1/

您可以使用pseudoelement来保存背景图像,而不会影响其他内容。

要去除深色边缘,您可以使用transform: scale().这将创建滚动条,因此您需要将.intro设置为overflow: hidden。您也可以尝试使用定位来删除边缘。

小提琴

.intro {
height: 100%;
position: relative;
overflow: hidden;
}
.intro::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: url('http://i.imgur.com/hNPuImp.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 100%;
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
transform: scale(1.1);
}

最新更新