CSS模糊效果略微抽搐元素

时间:2018-01-17 05:31:54

标签: html css blur

当我尝试使用模糊效果时,它会稍微抽搐一下我的元素。

有人可以帮我解决这个问题吗?

$bg: rgba(0, 0, 0, 0.2);

*,
*:before,
*:after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.container {
  width: 85vw;
  margin: 1rem auto;
}


.bg,
.overlay {
  text-align: center;
}

img,
.overlay {
  transition: .3s all;
  border-radius: 3px;
}

.bg {
  float: left;
  max-width: 31%;
  position: relative;
  margin: .5%;
  img {
    width: 100%;
    margin-bottom: -4px;
  }
  .overlay {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    background: $bg;
    color: #fff;
    opacity: 0;
    h2 {
      padding-top: 20%;
      font-family: 'Droid Serif', serif;
    }
    p {
      font-family: 'Julius Sans One', sans-serif;
    }
  }
  &:hover {
    .overlay {
      opacity: 1;
    }
    img {
      -webkit-filter: blur(2px);
      filter: blur(2px);
    }
  }
}

@media screen and (max-width: 1148px) {
  .bg {
    max-width: 48%;
    margin: 1%;
  }
}

@media screen and (max-width: 768px) {
  .bg {
    float: none;
    max-width: 80%;
    margin: 1% auto;
  }
}
<div class="container">
  <div class="bg">
    <img src="https://unsplash.it/400/200" alt="">
    <div class="overlay">
      <h2>Check This <span>Out!</span></h2>
      <p>this is some text.</p>
    </div>
  </div>
  <div class="bg">
    <img src="https://unsplash.it/400/200" alt="">
    <div class="overlay">
      <h2>Check This <span>Out!</span></h2>
      <p>this is some text.</p>
    </div>
  </div>
  <div class="bg">
    <img src="https://unsplash.it/400/200" alt="">
    <div class="overlay">
      <h2>Check This Out!</h2>
      <p>this is some text.</p>
    </div>
  </div>
</div>

Check Codepen link

1 个答案:

答案 0 :(得分:-4)

p:hover {-webkit-filter:blur(5px); -moz-filter:blur(5px); -o-filter:blur(5px); -ms-filter:blur(5px); filter:blur(5px);}