【问题标题】:Bootstrap-Multiselect: Dropdown is underneatch outer container if overflow-y is usedBootstrap-Multiselect:如果使用溢出-y,则下拉菜单低于外部容器
【发布时间】:2023-03-16 01:35:01
【问题描述】:

我正在使用 Bootstrap-Multiselect (link) ...当外部容器有一个 overflow-y: scroll 和一个 max-height ...多选的下拉菜单消失了。如何让它显示在过滤器容器上?

HTML:

<div class="container filter-container">    

 <div class="row">
  <div class="col-md-12 search-box">          
      <div class="col-md-12">
        <form role="form-inline">
          <div class="form-group search-form-group">
            <label class="search-label">Users:</label>
            <div class="mid-width">
              <select class="select-users form-control"></select>
            </div>
          </div>
        </form>    
      </div>                                                                                        
  </div>  
 </div>  

</div>  

CSS:

.filter-container {
    padding: 1%;
    border: 1px solid #eee;
    max-height: 100px;
    overflow-y: scroll;
    background-color: #f8f8f8;
}

JS:

$(document).ready(function() {
  $('.select-users').multiselect({
        maxHeight: 400,
        buttonWidth: '100%' 
    });
    var accounts = [
        { label: 'UserID 1', value: '1' },
        { label: 'UserID 2', value: '2' },      
        { label: 'UserID 3', value: '3' }, 
        { label: 'UserID 4', value: '4' },         
        { label: 'All', value: '' }  
        ];  

    $('.select-users').multiselect('dataprovider', accounts);  
});

Fiddle

我认为https://github.com/davidstutz/bootstrap-multiselect/issues/382 也解决了这个问题。

【问题讨论】:

  • 您到底想达到什么目的?为什么首先需要溢出-y?在该 div 上设置 max-height 和 overflow-y 后,它将始终出现在该容器中
  • 我在过滤器容器中有一组多重选择(大约 15 个)......并且由于过滤器容器变得很长......这就是我想要溢出的原因:滚动它...... .filter-container 也是一个可协作的容器
  • 您可以使用内置的 html 选择,它将位于容器上方,但您将不会使用 bs 多选功能,如果仍然可行,我建议重新设计解决方案和/或扩大整个过滤器 div,可能会覆盖某种模式样式框中的所有内容,我认为您正在尝试的方法受到浏览器和 html 规范的限制

标签: jquery html css twitter-bootstrap bootstrap-multiselect


【解决方案1】:

在你的 CSS 中添加一个类

.multiselect-container {
  position:relative;
}

Fiddle

【讨论】:

  • ...但是过滤器容器变大(高度)...我希望它保持在最大值:100px
  • 在这种情况下,您需要将下拉菜单放在 div 之外,
  • ... 但我想把它放在定义的 div .filter-container
【解决方案2】:

试试这个

<select class="selectpicker" multiple>
  <option>Mustard</option>
  <option>Ketchup</option>
  <option>Relish</option>
</select>

下面的例子 click

【讨论】:

    猜你喜欢
    • 2014-12-29
    • 2022-09-29
    • 2015-10-28
    • 2022-06-13
    • 1970-01-01
    • 2020-12-15
    • 2021-10-14
    • 1970-01-01
    • 2018-07-07
    相关资源
    最近更新 更多