gpt4 book ai didi

html - 用另一张图片覆盖 body 背景

转载 作者:太空宇宙 更新时间:2023-11-04 16:02:27 26 4
gpt4 key购买 nike

我正试图用另一张图片覆盖 html 正文背景图片。我使用了 z-index 但无法正常工作。我是不是遗漏了什么,或者只是无法理解我在做什么。

参见下面的示例代码:

body, html {
margin: 0;
/* The image used */
background-image: url('http://lorempixel.com/output/nature-q-c-1176-907-10.jpg');

/* Full height */
height: 100%;

/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}

#main-content {
background-image: url('http://lorempixel.com/output/food-q-c-640-633-1.jpg');
z-index: 10;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
position: relative;
}

.content {
/*height: 700px;*/
height: 100vh;
background:rgba(255,255,255,0.5);
/*margin-top: 20%;*/
}
<div id="main-content">
<div class="content">something in here..</div>
<div class="content">something in here..</div>
<div class="content">something in here..</div>
</div>

Additionaly, inside the main-content are divs with 100vh and background opacity

主要内容图像应该位于所有内容之上,包括背景不透明的 content div。

最佳答案

#main-content 上使用100% 宽度和高度,例如:

#main-content {
width: 100%;
height: 100%;
}

看看下面的片段:

body, html {
margin: 0;
/* The image used */
background-image: url('http://lorempixel.com/output/nature-q-c-1176-907-10.jpg');

/* Full height */
height: 100%;

/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}

#main-content {
background-image: url('http://placehold.it/500x500');
z-index: 10;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
position: relative;
width: 100%;
height: 100%;
}
<div id="main-content"></div>

希望这对您有所帮助!

关于html - 用另一张图片覆盖 body 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40934025/

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