在左右显示导航栏时,下拉总是最后显示,它应该在其他链接和下拉内容重叠下拉按钮之间。
下拉内容与下拉内容重叠。如何纠正?
body {
color: #959595;
}
.navbar {
width: 100%;
}
.nav-left {
float: right;
width: 25%;
position: absolute;
padding-top: 14px;
}
.navbar-Logo {
float: right;
color: #dd845a;
text-decoration: none;
}
.navbar-Logo a {
float: right;
color: #dd845a;
text-decoration: none;
}
.navbar-Logo:hover,
.navbar-Logo:focus {
color: sienna;
background-color: transparent;
}
.nav-right {
width: 75%;
float: right;
background-color: #fff;
}
.nav-right a {
display: inline;
color: black;
/*text-align: center;*/
padding-left: 14px;
text-decoration: none;
}
.rightbar_items {
float: left;
color: #dd845a;
text-decoration: none;
}
#rb {
float: right;
padding: 14px 16px;
}
.dropdown {
display: inline-block;
}
.dropdown .dropbtn {
border: none;
outline: none;
color: black;
background-color: inherit;
/*font-family: inherit;*/
margin: 0;
float: left;
}
.nav-right a:hover {
background-color: #E7E7E7;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
background-color: white;
text-align: left;
}
.dropdown-content {
display: none;
position: absolute;
background-color: black;
}
.dropdown-content a:hover {
background-color: #ddd;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Navigation -->
<div class="navbar">
<div class="nav-left">
<a class="navbar-Logo" href="#">LOGO</a>
</div>
<div class="nav-right">
<div id="rb">
<a class="rightbar_items" href="#">Home</a>
<a class="rightbar_items" href="#">Products</a>
<div class="dropdown">
<button class="dropbtn">Services
<i class="fa fa-caret-down"></i></button>
<div class="dropdown-content">
<a href="#">abc</a>
<a href="#">def</a>
<a href="#">ghi</a>
</div>
</div>
<a class="rightbar_items" href="#">My Account</a>
<a class="rightbar_items" href="#">My Cart</a>
</div>
</div>
</div>
答案 0 :(得分:0)
将 top: 40px;
添加到 .dropdown-content
并取出除 .nav-right
中的浮点数之外的所有浮点数。
body {
color: #959595;
}
.navbar {
width: 100%;
}
.nav-left {
width: 25%;
position: absolute;
padding-top: 14px;
}
.navbar-Logo {
color: #dd845a;
text-decoration: none;
}
.navbar-Logo a {
color: #dd845a;
text-decoration: none;
}
.navbar-Logo:hover,
.navbar-Logo:focus {
color: sienna;
background-color: transparent;
}
.nav-right {
width: 75%;
float: right;
background-color: #fff;
}
.nav-right a {
display: inline;
color: black;
/*text-align: center;*/
padding-left: 14px;
text-decoration: none;
}
.rightbar_items {
color: #dd845a;
text-decoration: none;
}
#rb {
padding: 14px 16px;
}
.dropdown {
display: inline-block;
}
.dropdown .dropbtn {
border: none;
outline: none;
color: black;
background-color: inherit;
/*font-family: inherit;*/
margin: 0;
}
.nav-right a:hover {
background-color: #E7E7E7;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 80px;
/* added top: 40px */
top: 40px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
background-color: white;
text-align: left;
}
.dropdown-content {
display: none;
position: absolute;
background-color: black;
}
.dropdown-content a:hover {
background-color: #ddd;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Navigation -->
<div class="navbar">
<div class="nav-left">
<a class="navbar-Logo" href="#">LOGO</a>
</div>
<div class="nav-right">
<div id="rb">
<a class="rightbar_items" href="#">Home</a>
<a class="rightbar_items" href="#">Products</a>
<div class="dropdown">
<button class="dropbtn">Services
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">abc</a>
<a href="#">def</a>
<a href="#">ghi</a>
</div>
</div>
<a class="rightbar_items" href="#">My Account</a>
<a class="rightbar_items" href="#">My Cart</a>
</div>
</div>
</div>