【问题标题】:How do I add a scroll to the dropdown menu?如何在下拉菜单中添加滚动条?
【发布时间】:2020-07-28 21:14:26
【问题描述】:

我正在尝试创建一个下拉菜单,当内容不适合屏幕时,我可以在其中滚动。但是,这并没有按我的意愿工作,因为当文本离开屏幕时没有出现任何滚动条。

我该怎么做呢?

这是我的代码:

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>

【问题讨论】:

  • 您需要将该代码放入代码 sn-p 而不是谷歌文档中才能被查看。
  • 我知道不让我。如果有人可以编辑我的帖子而不会引发错误,欢迎您...

标签: html css drop-down-menu scroll scrollable


【解决方案1】:

谢谢大家。我找到了解决方案。基本上我需要给出下拉列表的大小。否则,CSS 不会让我放滚动条。

【讨论】:

    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 2014-06-02
    • 2019-02-27
    • 2016-12-16
    • 2020-03-27
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    相关资源
    最近更新 更多