我正在尝试在另一张图片的顶部添加图片,但我希望背景图片模糊,第二张图片正常
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;
答案 0 :(得分:1)
您可以将:before
伪类用于模糊背景,将 Flexbox 用于图像的中心对齐
Stack Snippet
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;