我在页面的左侧有一个垂直的导航栏,并有一个带有下拉菜单的顶部标题,当其中一项被下拉时,导航栏显示在下拉菜单的顶部,当我有{{ 1}},当我更改z-index: 0
时,导航栏显示在下拉菜单下,但链接不再可单击。
我尝试将z-index: -1
中的z-index
更改为非常高的值,但它仍显示在顶部。
我该怎么做才能使导航栏显示在叠加层下,但仍可单击该项目?
这是相关的CSS:
.sub-content
可点击,但显示在叠加层nav.right>ul {
overflow: auto;
list-style: none;
margin-left: 0;
padding-left: 0;
height: calc(100vh - 80px);
position: sticky;
z-index: 0;
top: 60px;
}
上方:
z-index: 0
nav.right>ul {
overflow: auto;
list-style: none;
margin-left: 0;
padding-left: 0;
height: calc(100vh - 80px);
position: sticky;
z-index: 0;
top: 60px;
}
a { color: skyblue; }
main {
display: flex;
margin: auto;
}
main>nav {
width: 20%;
}
main {
width: 80%;
padding-left: 20px;
}
.sub-content>div>ul {
list-style-type: none;
}
.sub-content {
position: absolute;
left: 0;
right: 0;
padding: 0;
display: none;
background: #292929;
padding: 5vh 0;
}
.sub-content>div:first-child {
width: 25vw;
position: relative;
left: 0;
right: 0;
margin: auto;
}
nav.top>ul>li:hover>.sub-content {
display: block;
}
.sub-content>div>ul>li>a {
color: #ffffff;
padding: 5px 10px;
font-size: 0.9rem;
text-decoration: none;
display: block;
}
.sub-content>div>ul>li>a:hover {
/* background: #ee2012; */
text-decoration: underline;
}
nav.top {
background: #f44336;
display: flex;
flex-direction: row;
justify-content: center;
position: sticky;
top: 0;
}
nav.top>ul {
margin: 0;
display: flex;
flex-direction: row;
list-style-type: none;
}
nav.top>ul>li>a {
display: inline-block;
padding: 1rem 1.5rem;
color: #ffffff;
text-decoration: none;
}
nav.top>ul>li>a:hover,
nav.top>ul>li>a.router-link-exact-active {
background: #ee2012;
}
不可点击,但显示在叠加层<nav class="top">
<ul>
<li>
<a href="">Item</a>
<div class="sub-content">
<div>
<ul>
<li><a href="">Sub Item</a></li>
<li><a href="">Sub Item</a></li>
</ul>
</div>
</div>
</li>
</ul>
</nav>
<main>
<nav class="right">
<ul>
<li><a href="">Abc</a></li>
<li><a href="">Abc</a></li>
<li><a href="">Abc</a></li>
<li><a href="">Abc</a></li>
<li><a href="">Abc</a></li>
<li><a href="">Abc</a></li>
<li><a href="">Abc</a></li>
<li><a href="">Abc</a></li>
<li><a href="">Abc</a></li>
<li><a href="">Abc</a></li>
</ul>
</nav>
<div class="content">
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
<p>Dummy Text</p>
</div>
</main>
下:
z-index: -1
nav.right>ul {
overflow: auto;
list-style: none;
margin-left: 0;
padding-left: 0;
height: calc(100vh - 80px);
position: sticky;
z-index: -1;
top: 60px;
}
a { color: skyblue; }
main {
display: flex;
margin: auto;
}
main>nav {
width: 20%;
}
main {
width: 80%;
padding-left: 20px;
}
.sub-content>div>ul {
list-style-type: none;
}
.sub-content {
position: absolute;
left: 0;
right: 0;
padding: 0;
display: none;
background: #292929;
padding: 5vh 0;
}
.sub-content>div:first-child {
width: 25vw;
position: relative;
left: 0;
right: 0;
margin: auto;
}
nav.top>ul>li:hover>.sub-content {
display: block;
}
.sub-content>div>ul>li>a {
color: #ffffff;
padding: 5px 10px;
font-size: 0.9rem;
text-decoration: none;
display: block;
}
.sub-content>div>ul>li>a:hover {
/* background: #ee2012; */
text-decoration: underline;
}
nav.top {
background: #f44336;
display: flex;
flex-direction: row;
justify-content: center;
position: sticky;
top: 0;
}
nav.top>ul {
margin: 0;
display: flex;
flex-direction: row;
list-style-type: none;
}
nav.top>ul>li>a {
display: inline-block;
padding: 1rem 1.5rem;
color: #ffffff;
text-decoration: none;
}
nav.top>ul>li>a:hover,
nav.top>ul>li>a.router-link-exact-active {
background: #ee2012;
}