html - z-index 问题,sidenav 重叠 topnav

标签 html css

希望有人能发现我遗漏的内容,我正在处理同时包含顶部导航和侧边导航的页面。我希望 topnav 保持在最上面。我希望 sidenav 在它下面,而不重叠它。

这是我的 fiddle您可以通过点击橙色汉堡包按钮来访问 sidenav。

我以前让它工作,但最近对我的顶部导航做了一些调整,现在它只是拒绝合作。不胜感激。

这是 CSS:

body {
margin:0;
color: #2C3E60;
font-size: ; 
font-family: arial;  
font-weight: bold;
font-family: ; 
line-height: 1.2;
overflow: hidden;
}

form {
margin: 0px;
padding: 0px;
}
.main {
padding: 0px; 
margin-top: 0px;
width: 100%;
height: 91%;
position:absolute;
overflow-y:auto;
background-color: #ec7c23;
}


.navbar {
overflow: hidden;
background-color: #577CC1;
min-height: 71px; 
possition: fixed;
/*z-index: 2;*/
top: 0;
width: 100%;
line-height: 1.07;
font-size: 3em;
}

.navbar a {
float: left;
display: block;
color: #ffffff;
text-align: center;
padding: 10px 10px;
text-decoration: ;
font-size: 40px;
font-weight: bold;
}

.active {
background-color: #4CAF50;
color: white;
}

.navbar .icon {
display: none;
}

.dropdown {
float: left;
overflow: hidden;
}

.dropdown .dropbtn {
font-size: 17px;    
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
font-weight: bold;
margin: 0;
height: 71px;
}

.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
background-color: rgba(0, 42, 59, .8);
overflow: auto;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}

.dropdown-content a {
float: none;
color: #ffffff;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
font-size: 20px;
font-weight: bold;
}

.navbar a:hover, .dropdown:hover .dropbtn {
background-color: ;
color: white;
}

.dropbtn a:hover, .dropdown:hover .dropbtn {
background-color: #2C3E60;
color: white;
}

.dropdown-content a:hover {
background-color: #577CC180;
color: black;
}

.dropdown:hover .dropdown-content {
display: block;
}

@media screen and (max-width: 600px) {
.navbar a:not(:first-child), .dropdown .dropbtn {
display: none;
}
.navbar a.icon {
float: right;
display: block;
}
}

@media screen and (max-width: 600px) {
.navbar.responsive {position: relative;}
.navbar.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.navbar.responsive a {
float: none;
display: block;
text-align: left;
color: white;
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
}
.navbar.responsive .dropdown {float: none ;
}
.navbar.responsive .dropdown-content {
position: relative;         
border-bottom-left-radius: 0px;
border-bottom-right-radius: 0px;
}
.navbar.responsive .dropdown .dropbtn {
display: block;
width: 100%;
text-align: left;
}
}


.container {
display: inline-block;
cursor: pointer;
float: right;
}
.bar1, .bar2, .bar3 {
width: 35px;
height: 5px;
background-color: #ec7c23;
margin: 6px 0;
transition: 0.4s;
}
.change .bar1 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
transform: rotate(-45deg) translate(-9px, 6px) ;
}
.change .bar2 {opacity: 0;}
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-8px, -8px) ;
transform: rotate(45deg) translate(-8px, -8px) ;
}


.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 9;
top: 0;
right: 0;
background-color: rgba(0, 42, 59, .8);  
font-weight: ;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #577CC1;
display: block;
transition: 0.3s;
}
.sidenav a:hover, .offcanvas a:focus{
color: #ec7c23;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
z-index: 10;
}
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}



button.accordion {
background-color: #577CC1;
color: white;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
font-family: arial;
font-weight: bold; 
line-height: 1.2;
transition: 0.4s;
z-index: 5;
}
button.accordion.active, button.accordion:hover {
background-color: #2C3E60;
}
div.panel {
padding: 0 18px;
display: none;
background-color: rgba(0, 0, 0, 0.0);
color: #2C3E60;
font-size: ; 
font-family: arial;
font-weight: bold;
line-height: 1.2;
}

最佳答案

只需更正您的 .navbar 类中的拼写错误

position: fixed;position: fixed;

关于html - z-index 问题,sidenav 重叠 topnav,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56745285/

相关文章:

html - 当客户端选择或输入时,我如何感知?

php - Firebug 显示位于 "wp-login.php #3 (line 25)"中的 CSS 源代码。找不到这个文件

html - slider 过渡在 Firefox 中不起作用

html - 忽略正文的文本对齐

html - 如何为已清除的元素提供 margin ?

html - 一些 div 元素留在顶部(页面外)

html - 在不影响页面设计的情况下在html页面上显示从mysql接收到的数据

html - 在多选选项中添加图标?

支持查询的CSS预处理器

jquery - 隐藏在其他元素上的 CSS 菜单