如何在另一个模糊图像上添加图像

时间:2018-01-27 13:25:56

标签: html css

我正在尝试在另一张图片的顶部添加图片,但我希望背景图片模糊,第二张图片正常



header {
  background-image: linear-gradient(rgba(0, 0, 0, 0.60), rgba(0, 0, 0, 0.60)), url(img.jpg);
  height: 85vh;
  background-size: cover;
  background-position: center;
  filter: blur(8px);
}

img {
  width: 500px;
  height: auto;
  margin-left: 50%;
  margin-top: 10%;
}

<header>
  <img src="img.jpg" alt="img">
</header>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

您可以将:before伪类用于模糊背景,将 Flexbox 用于图像的中心对齐

Stack Snippet

&#13;
&#13;
body {
  margin: 0;
}

header {
  height: 85vh;
  display: flex;
  overflow: hidden;
  position: relative;
}

header:before {
  content: "";
  filter: blur(8px);
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-image: url(http://www.planwallpaper.com/static/images/general-night-golden-gate-bridge-hd-wallpapers-golden-gate-bridge-wallpaper.jpg);
  z-index: -1;
}

img {
  max-width: 100%;
  height: auto;
  margin: auto;
}
&#13;
<header>
  <img src="http://via.placeholder.com/350x150" alt="img">
</header>
&#13;
&#13;
&#13;