gpt4 book ai didi

html - Unblur 模糊背景 div 中的内容

转载 作者:太空宇宙 更新时间:2023-11-03 22:19:28 26 4
gpt4 key购买 nike

所以我很喜欢这里的这种特效https://www.w3schools.com/howto/howto_css_blurred_background.asp您可以在其中模糊背景并显示文本。我现在遇到的问题是我想在我的第一个内容下方为我的第二个内容添加另一个墙纸。第一个内容不错。现在我希望我的第二个内容在您滚动时出现在第二个墙纸中。有点像创建视差效果,但我正在创建自己独特的网站。

这一次我想要一个模糊的背景(二号墙纸),同时在我想要放置的地方放置东西并使其聚焦。

有什么办法可以实现吗?

bg-image2 的起始位置, 我想要 h1 , 和 p , 里面 bg-image2将焦点放在模糊的背景图像上。

注意: 墙纸不会显示在下面的片段中,因为我已经在我的计算机文件夹中找到了我需要的图片。

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>

最佳答案

这是您想要的结果吗?

https://codepen.io/anon/pen/exVRyy

我所做的就是围绕 bg-image2profilePicture 创建一个 div,这样 bg-image2 上的模糊就不会了'不影响 profilePicture,然后将该 div 设置为 position:relative; ,这样 profilePicture 就可以像您一样放在中间。

这是您编辑的 HTML:

<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-test">
<div class="bg-image2">

<!-- This is the part where I want my stuff to not be blurred and focus -->

</div>

<div class="profilePicture">
<img src="https://images.pexels.com/photos/1253661/pexels-photo-1253661.jpeg?cs=srgb&dl=android-wallpaper-bluhen-blume-1253661.jpg&fm=jpg" style="width: 170px; height: 170px; border-radius:50%;">
<h1>This is a title</h1>
<p>This is just a paragraph</p>
</div>
</div>

还有 CSS:

body,
html {
height: 100%;
}

* {
box-sizing: border-box;
}

.bg-image {
/* The image used */
background-image: url("https://images.unsplash.com/photo-1507608616759-54f48f0af0ee?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80");
/* 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-test {
position:relative;
}

.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("https://whatthenewsblog.files.wordpress.com/2015/03/ecl-ann.jpg");
/* Add the blur effect */
filter: blur(8px);
-webkit-filter: blur(8px);
/* Full height */
height: 100vh;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}

.profilePicture {
position: absolute;
left: 50%;
top:50%;
margin: 0 auto;
transform: translate(-50%, -50%);
}

关于html - Unblur 模糊背景 div 中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54599352/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com