【发布时间】:2019-07-03 02:31:43
【问题描述】:
所以我真的很喜欢https://www.w3schools.com/howto/howto_css_blurred_background.asp 的这种特殊效果,您可以在其中模糊背景并显示文本。我目前遇到的问题是我想在我的第一个内容下方为我的第二个内容添加另一个壁纸。第一个内容不错。现在我希望我的第二个内容在您滚动时出现在第二个壁纸中。有点像创建视差效果,但我正在创建自己独特的网站。
这一次我想要一个模糊的背景(第二张壁纸),同时将我想要的东西放在我想要的位置并让它聚焦。
有没有办法做到这一点?
从bg-image2 开始,我想要h1 和p,在bg-image2 内聚焦模糊的背景图像。
注意: 壁纸不会显示在下面的 sn-p 中,因为我已经在位于我的计算机中的文件夹中找到了我需要的图片.
body,
html {
height: 100%;
}
* {
box-sizing: border-box;
}
.bg-image {
/* The image used */
background-image: url("images/wallpaper1.jpg");
/* Add the blur effect */
filter: blur(8px);
-webkit-filter: blur(8px);
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
/* Position text in the middle of the page/image */
.bg-text {
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.4);
/* Black w/opacity/see-through */
color: white;
font-weight: bold;
border: 3px solid #f1f1f1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
width: 80%;
padding: 20px;
text-align: center;
}
.bg-image2 {
/* The image used */
background-image: url("images/wallpaper2.jpg");
/* Add the blur effect */
filter: blur(8px);
-webkit-filter: blur(8px);
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.profilePicture {
position: absolute;
left: 50%;
margin: 200px auto;
transform: translate(-50%, -50%);
}
<div class="bg-image"></div>
<div class="bg-text">
<h1>My name is Stackoverflow</h1>
<p>And I am a website</p>
</div>
<div class="bg-image2">
<!-- This is the part where I want my stuff to not be blurred and focus -->
<div class="profilePicture">
<img src="images/profilePic.jpg" style="width: 170px; height: 170px; border-radius:50%;">
<h1>This is a title</h1>
<p>This is just a paragraph</p>
</div>
</div>
【问题讨论】:
-
您能不能在将背景图像作为背景图像之前先用过滤器(使用 Photoshop 之类的东西)模糊背景图像,然后将过滤器 css 全部移除?
-
@KJEK-Code 对的好点。我想我会坚持使用其他工具对照片进行造型,然后让我的网站变得有点复杂,因为所有这些疯狂的编码。
-
Azazel 祝你好运
标签: html css background-image wallpaper