gpt4 book ai didi

html - 与具有较低 z-index 的元素交互

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

我的边栏有问题。

html, body {
height: 100%;
margin: 0;
}
.sidebar{
display: inline-block;
height: 100%;
width: 100px;
box-shadow: 3px 0px 100px 0px rgba(0, 0, 0, 0.16);
background-color: #fff;
}
.content {
position: absolute;
top: 0;
padding-left: 100px;
width: 100%;
height: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-color: #EEF2F8;
z-index: -1
}
.section {
display: block;
height: 100px;
background-color: #fff;
}
<div class="sidebar">

</div>

<div class="content">
<div class="section">
<a href="#">You can't interact with me :(</a>
</div>
</div>

我需要与内容进行交互,但是当我在 .content 上放置更高的 z-index 时,阴影将不再显示。所以我可以将背景与 .content 分开,但我想添加具有不同背景的部分,它们也不会有阴影。

我也做了侧边栏不覆盖整个屏幕,但你仍然不能与右侧互动。

最佳答案

问题是在您的内容上将 z-index 设置为 -1。不要在背景中的元素上设置负值,而应在应该在前面的元素上设置更高的值。如果将位置设置为相对,则可以向侧边栏添加 z-index 值并获得所需的行为。

html, body {
height: 100%;
margin: 0;
}
.sidebar{
position: relative;
z-index: 1;
display: inline-block;
height: 100%;
width: 100px;
box-shadow: 3px 0px 100px 0px rgba(0, 0, 0, 0.16);
background-color: #fff;
}
.content {
position: absolute;
top: 0;
padding-left: 100px;
width: 100%;
height: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-color: #EEF2F8;
}
.section {
display: block;
height: 100px;
background-color: #fff;
}
<div class="sidebar">

</div>

<div class="content">
<div class="section">
<a href="#">You can interact with me :)</a>
</div>
</div>

关于html - 与具有较低 z-index 的元素交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48064359/

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