CSS滤镜模糊不会模糊边缘

时间:2016-06-07 20:52:10

标签: css css-filters

当我将模糊滤镜应用于我的标记时,边缘不会模糊。我希望整个地区都模糊不清。

HTML

<div class="container">
  <div class="inner">
    <div class="image">

    </div>
  </div>
</div>

CSS

.container {
  width: 300px;
  height: 250px;
}

.inner {
  width: 100%;
  height: 100%;
  position: relative;
}

.image {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: url(/images/400x300.jpg) no-repeat center center fixed;
  background-size: fill;
}

.image:before {
  left: 0;
  right: 0;
  bottom: 0px;
  content: "text";
  position: absolute;
  height: 20%;
  width: 100%;
  background: url(/images/400x300.jpg)  no-repeat center center fixed;
  background-size: fill;
  -webkit-filter: blur(12px);
  filter: blur(12px);
}

Codepen:

http://codepen.io/aaronbalthaser/pen/qNOYdE

Codepen显示模糊区域。它有点像页脚,但你可以看到边缘不模糊。有什么想法吗?

由于

1 个答案:

答案 0 :(得分:0)

您可以设置overflow: hidden并稍微拉伸模糊图像。我已将width设置为110%,高度设置为35%leftrightbottom设置为-5%(增加的百分比)到widthheight)。希望这是你想要的。

html,
body{
  width: 100%;
  height: 100%;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

.container {
  width: 300px;
  height: 250px;
}

.inner {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.image {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: url(http://attic24.typepad.com/.a/6a00e551101c548834017d3d4fde82970c-500wi) no-repeat center center fixed;
  background-size: fill;
}

.image:before {
  left: -5%;
  right: -5%;
  bottom: -5%;
  content: "";
  position: absolute;
  height: 35%;
  width: 110%;
  background: url(http://attic24.typepad.com/.a/6a00e551101c548834017d3d4fde82970c-500wi)  no-repeat center center fixed;
  background-size: fill;
  -webkit-filter: blur(8px);
  filter: blur(8px);
  overflow: hidden;
}
 <div class="container">
   <div class="inner">
     <div class="image">

     </div>
   </div>
 </div>