如何向下拉菜单添加滚动条?
How do I add a scroll to the dropdown menu?
我正在尝试创建一个下拉菜单,当内容不适合屏幕时我可以在其中滚动。然而,这并没有像我想要的那样工作,因为当文本离开屏幕时没有出现任何滚动条。
我应该怎么做?
这是我的代码:
body {
overflow-y: hidden;
}
.dropbtn {
height: 28px;
width: 50px;
padding: 16px;
font-size: 16px;
border: none;
}
.Panel {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 300px;
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;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.Panel:hover .dropdown-content {
display: block;
overflow: auto;
}
.Panel:hover .dropbtn {
background-size: 28px 50px;
background-repeat: no-repeat;
height: 50px;
width: 28px;
margin-left: 30px;
}
<body>
<div class="Panel">
<button class="dropbtn"></button>
<div id="myDropdown" class="dropdown-content">
<br> <br>
<a href="../" target="_self"> Home</a> <be>
<a href="../" target="_self"> Other</a> <br>
<a href="../" target="_self"> Other</a> <br>
<a href="../" target="_self"> Other</a> <br>
<a href="../" target="_self"> Other</a> <br>
</div>
</div>
</body>
谢谢大家。我找到了解决方案。基本上我需要给出下拉列表的大小。不然CSS不让我放卷轴
我正在尝试创建一个下拉菜单,当内容不适合屏幕时我可以在其中滚动。然而,这并没有像我想要的那样工作,因为当文本离开屏幕时没有出现任何滚动条。
我应该怎么做?
这是我的代码:
body {
overflow-y: hidden;
}
.dropbtn {
height: 28px;
width: 50px;
padding: 16px;
font-size: 16px;
border: none;
}
.Panel {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 300px;
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;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.Panel:hover .dropdown-content {
display: block;
overflow: auto;
}
.Panel:hover .dropbtn {
background-size: 28px 50px;
background-repeat: no-repeat;
height: 50px;
width: 28px;
margin-left: 30px;
}
<body>
<div class="Panel">
<button class="dropbtn"></button>
<div id="myDropdown" class="dropdown-content">
<br> <br>
<a href="../" target="_self"> Home</a> <be>
<a href="../" target="_self"> Other</a> <br>
<a href="../" target="_self"> Other</a> <br>
<a href="../" target="_self"> Other</a> <br>
<a href="../" target="_self"> Other</a> <br>
</div>
</div>
</body>
谢谢大家。我找到了解决方案。基本上我需要给出下拉列表的大小。不然CSS不让我放卷轴