gpt4 book ai didi

html - 具有负 z-index 的固定 block 与主体背景重叠

转载 作者:行者123 更新时间:2023-11-28 17:05:47 25 4
gpt4 key购买 nike

我有一个固定定位和负 z-index 的 block ,我想在主体后面:

html, body {
min-height: 100%;
}
body {
position: relative;
background: green;
}
.sidebar {
z-index: -999;
position: fixed;
top: 0; right: 0;
min-height: 100%; width: 200px;
background: red;
}

http://jsfiddle.net/3kcqfbuv/

但是,由于我不知道的原因,它位于正文内容的后面,但与明确定义的正文背景保持重叠。有什么办法可以解决吗?

最佳答案

Body 不是可以与任何其他层重叠的实际层...

解决您想要的问题的一个解决方案是创建另一个 div 层作为您的桌面/正文。

<style>
html, body, .desktop {
min-height: 100%;
}
.desktop {
background: green;
position:absolute;
top:0;left:0;
width: 100%;
}
.sidebar {
z-index: -999;
position: fixed;
top: 0; right: 0;
min-height: 100%; width: 200px;
background: red;
}
</style>

<div class="desktop">
<div class="content">
Pellentesque mollis diam at egestas lacinia. In a pharetra risus. Aenean in libero.
Nam sollicitudin at erat quis maximus. Nam aliquet ornare nibh, sit amet.
</div>
</div>

<div class="sidebar"></div>

关于html - 具有负 z-index 的固定 block 与主体背景重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30388963/

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