2017-07-05 55 views
0

我的问题是,如果我将鼠标悬停在下拉菜单上,它不会超出菜单本身的大小。我知道我有这个问题,因为固定的导航栏,但我仍然想保持它。任何解决方案如何在我的导航栏中修复此下拉菜单?

我的HTML的NavBar和CSS:

ul { 
 
    list-style-type: none; 
 
    margin: 0; 
 
    padding: 0; 
 
    overflow: hidden; 
 
    background-color: #333; 
 
} 
 

 
li { 
 
    float: left; 
 
} 
 

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

 
li a:hover, .dropdown:hover .dropbtn { 
 
    background-color: blue; 
 
} 
 

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

 
.dropdown-content { 
 
    display: none; 
 
    position: absolute; 
 
    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: 20px 20px; 
 
    text-decoration: none; 
 
    display: block; 
 
    text-align: left; 
 
} 
 

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

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

 
body { 
 
    margin:0; 
 
    background-color: #f8f8f8; 
 
    padding-top: 80px; 
 
    position: center; 
 
} 
 

 
.navbar { 
 
    overflow: hidden; 
 
    background-color: white; 
 
    position: fixed; 
 
    top: 0px; 
 
    width: 100%; 
 
} 
 

 
.navbar a { 
 
    float: left; 
 
    display: block; 
 
    color: black; 
 
    text-align: center; 
 
    padding: 14px 16px; 
 
    text-decoration: none; 
 
    font-size: 18px; 
 
    font-family: 'Lato', sans-serif; 
 
} 
 

 
.navbar a:hover { 
 
    background-color: lightgrey; 
 
} 
 

 

 
.main { 
 
    padding: 16px; 
 
    margin-top: 30px; 
 
    height: 1500px; /* Used in this example to enable scrolling */ 
 
}
<div class="navbar"> 
 
    <a><img src="Bilder/ITK_Logo.png" alt="Anscheinend gibt es ein Problem mit der Anzeige eines Bildes." width="100" height="16.6"></a> 
 
    <a href="#home">Home</a> 
 
    <li class="dropdown"> 
 
     <a href="#products" class="dropbtn">Produkte</a> 
 
     <div class="dropdown-content"> 
 
      <a href="">Amstweg</a> 
 
      <a href="">Mach mit!</a> 
 
      <a href="">Text</a> 
 
     </div> 
 
    </li> 
 
    <a href="#download">Download</a> 
 
    <a href="#about">Über uns</a> 
 
</div>

Picture of the Problem itself

+0

你能提供完整的HTML代码吗?我在测试时看不到内容下拉内容 –

回答

1
ul { 
    list-style-type: none; 
    margin: 0; 
    padding: 0; 
    background-color: #333; 
} 

li { 
    float: left; 
} 

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

li a:hover, .dropdown:hover .dropbtn { 
    background-color: blue; 
} 

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

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

.dropdown-content a { 
    color: black; 
    padding: 20px 20px; 
    text-decoration: none; 
    display: block; 
    text-align: left; 
} 

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

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

body { 
    margin:0; 
    background-color: #f8f8f8; 
    padding-top: 80px; 
    position: center; 
} 

.navbar { 
    background-color: white; 
    position: fixed; 
    top: 0px; 
    width: 100%; 
} 

.navbar a { 
    float: left; 
    display: block; 
    color: black; 
    text-align: center; 
    padding: 14px 16px; 
    text-decoration: none; 
    font-size: 18px; 
    font-family: 'Lato', sans-serif; 
} 

.navbar a:hover { 
    background-color: lightgrey; 
} 

.dropdown-content a { 
    width: 100%; 
    text-align: left; 
} 
.main { 
    padding: 16px; 
    margin-top: 30px; 
    height: 1500px; /* Used in this example to enable scrolling */ 
} 

上面的代码应该为你的下拉工作。 试试看。 这一定是你正在寻找的。谢谢

+0

但是我怎样才能解决这个问题:当我将鼠标悬停在下拉内容上时,悬停颜色比内容本身更长。所以它的范围不在下拉列表中 –