整个导航栏与下面的内容重叠

时间:2017-05-26 12:19:18

标签: html css

我的导航栏CSS问题。This is what happens when I hover over .dropbtn. 这是我下拉导航栏的HTML代码。

<div class="nav-wrapper">
<ul id="nav">
<a href="#home"><img id="logo" src="Images/dramay.jpg"></a>
  <li class="dropdown">

    <a href="#" class="dropbtn">Movies & TV &#9207;</a>

    <div class="dropdown-content">
      <a href="#" id="mov"><b style="font-size: 15px">MOVIES</b></a>
       <a href="#">In Theaters</a>
      <a href="#">Coming Soon</a>
      <a href="category.html">Categories</a>
       <a href="#">Most Popular</a>
       <a href="#" id="tv"><b style="font-size: 15px" > TV </b></a>
       <a href="#" >Timings</a>
       <a href="#">Latest shows</a>
       <a href="#">Top rated</a>
    </div>
  </li>

  <li class="dropdown">
    <a href="#" class="dropbtn">Celebs & photos &#9207;</a>
    <div class="dropdown-content">
    <a href="#"><b style="font-size: 15px">Celebs</b></a>
    <a href="#">Born today</a>
    <a href="#">Most popular</a>
    <a href="gallery.html"><b style="font-size: 15px">Photos</b></a>
    <a href="#">latest stills</a>
    <a href="#">Latest posters</a>

    </div>

  </li>
    <li class="dropdown">
    <a href="#" class="dropbtn">News &#9207;</a>
    <div class="dropdown-content">
      <a href="#"><b style="font-size: 15px">News</b></a>
      <a href="#">Top news</a>
      <a href="#">Movies news</a>
      <a href="#">TV news</a>
    </div>

  </li>

 <li class="search" style="float:right;"><a>
  <input type="text" name="firstname" placeholder="SEARCH">
 </a>
 </li>

    <li class="dropdown" id="signIN">
        <a href="signIN.html" class="dropbtn">Sign In</a>
    </li>
    <li class="dropdown" id="signUP">
        <a href="signUP.html" class="dropbtn">Sign Up</a>
    </li>

</ul>
</div>

这就是CSS。

ul#nav {
  list-style-type: none;
  margin: 0;
  padding: 0;
  position: inherit;
  width: 100%;
  overflow: hidden;
  background: #332;
}


.nav-wrapper
 {
   position: fixed;
   width: 100%;
}

li {
 float: left;
}

li a, .dropbtn {
  display: inline-block;
  color: lightgrey;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

li a:hover, .dropdown:hover .dropbtn {
   background-color:#00b300;
}

li a:hover, .search:hover  {
   background-color:black;

 }
li.dropdown {
  display: inline-block;
 }

.dropdown-content {
   display: none;
   color:black;
   position: relative;
   background-color: #f9f9f9;
   min-width: 160px;
   box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
   z-index: 1;
}

.dropdown-content a {
   color: black;
   padding: 12px 16px;
   text-decoration: none;
   display: block;
   text-align: left;
   font-size: 15px;
   z-index: 1; 
  }

 .dropdown-content a:hover {
 background-color: #f1f1f1;
  }

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

我试过溢出:隐藏在ul#nav和.nav-wrapper上,但没有一个有效。 (为我糟糕的英语提前道歉)

2 个答案:

答案 0 :(得分:0)

在你的CSS中进行2次更改: -

1)删除overflow: hidden;班级中的ul#nav

ul#nav {
  list-style-type: none;
  margin: 0;
  padding: 0;
  position: inherit;
  width: 100%;
  /*overflow: hidden;*/
  background: #332;
}

2)更改.dropdown-content

中的位置
.dropdown-content {
    background-color: #f9f9f9;
    box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
    color: black;
    display: none;
    min-width: 160px;
    position: absolute;
    z-index: 1;
}

答案 1 :(得分:0)

添加以下css

ul#nav {
    overflow: visible;
}
ul#nav li { 
    position: relative;
}
.dropdown-content {
    position: absolute;
    left: 0px;
    top: 100%;
}