我的问题是,如果我将鼠标悬停在下拉菜单上,它就不会超出菜单本身的大小。我知道我有这个问题,因为固定的导航栏,但我还是想保留它。任何解决方案?
我的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>
答案 0 :(得分: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 */
}
以上代码适用于您的下拉列表。 试试吧。 这一定是你要找的。谢谢