[英]JS: dropdown content can't be displayed when navbar is fixed
Once I added the line position:fixed into the .navbar to fix my navbar, the dropdown content could not be displayed anymore.一旦我将行 position:fixed 添加到 .navbar 以修复我的导航栏,下拉内容就无法再显示了。 Any Idea, how it could be and how can I fix the navbar in a right way here?任何想法,它怎么可能以及如何在这里以正确的方式修复导航栏?
<html>
<head>
<style>
.navbar {
position: fixed;
width: 200px;
overflow: hidden;
background-color: #333;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown-content {
display: none;
position: absolute;
}
.dropdown-content a {
text-decoration: none;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body>
<div class="navbar">
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
</div>
</div>
</div>
</body>
</html>
You shouldn't add overflow: hidden
in .navbar
, the right way:你不应该添加overflow: hidden
in .navbar
,正确的方法:
.navbar {
position: fixed;
width: 200px;
background-color: #333;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.