简体   繁体   English

使用 bootstrap-select 限制下拉列表的高度

[英]Limit the height of dropdown with bootstrap-select

How do you limit how many options are included in a select?您如何限制选择中包含的选项数量? I have around 2000 options (I am using data-live-search to make it easy to search), but I don't want to make an extremely long list (for aesthetic purposes).我有大约 2000 个选项(我使用 data-live-search 以便于搜索),但我不想列出一个非常长的列表(出于审美目的)。

I recently spent an hour trying to find how to restrict the height of a dropdown.我最近花了一个小时试图找到如何限制下拉菜单的高度。 Turns out the size attribute for select tags is set to 'auto' in the javascript file.结果是,在 javascript 文件中,选择标签的大小属性设置为'auto' For me, it was around line 369.对我来说,它大约在第 369 行。

The solution is simple:解决方法很简单:

Set size: '8' or however many options you want to be listed设置size: '8'或您想要列出的多个选项

size and data-size didn't work for me. sizedata-size对我不起作用。 I need to override CSS with this:我需要用这个覆盖 CSS:

div.dropdown-menu.open{
  max-height: 314px !important;
  overflow: hidden;
}
ul.dropdown-menu.inner{
  max-height: 260px !important;
  overflow-y: auto;
}

Change the size as you like.根据需要更改大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM