【发布时间】:2021-02-11 04:14:49
【问题描述】:
我在滚动 div 中有一个 Bulma 下拉菜单,但我希望下拉菜单忽略周围 div 的边界。
所以我知道这可以通过使用固定位置的一些技巧来实现,但我无法让它发挥作用。 如果可能的话,我也不想退出 bulma 下拉菜单。
我制作了这个代码笔来可视化我的问题:
https://codepen.io/meneman/pen/BaQLVwd
在 HTML 中,我有一个包装 div,它的溢出设置为滚动,还有一个内部 div,它比外部 div 大,用作滚动内容。此 div 还包含一个下拉列表,当它处于活动状态时,我希望在所有 div 上方可见。
<html>
<body>
<div id="scroll-wrapper">
<div id="inner-wrapper">
<!-- replace is-active with is-hoverable to have actual dropdown-->
<div class="dropdown is-active">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu2">
<span>Content</span>
<span class="icon is-small">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="dropdown-menu" id="dropdown-menu2" role="menu">
<div class="dropdown-content">
<div class="dropdown-item">
<p>You can insert <strong>any type of content</strong> within the dropdown menu.</p>
</div>
<hr class="dropdown-divider">
<div class="dropdown-item">
<p>You simply need to use a <code><div></code> instead.</p>
</div>
<hr class="dropdown-divider">
<a href="#" class="dropdown-item">
This is a link
</a>
</div>
</div>
</div>
</div>
</div>
</html>
</body>
css:
body {
display: flex;
background: lightgreen;
min-height: 100vh;
}
#scroll-wrapper {
background-color: lightblue;
margin: auto;
padding: 1rem;
height: 200px;
width :300px;
overflow-y: scroll;
}
#inner-wrapper {
height: 300px
}
【问题讨论】: