Html 限制选择框列表长度 - 添加滚动条
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5593004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
limiting select box list length - adding scrollbars
提问by tomermes
When i use an html select box which has about 50 items, I get a very long list that fully appears. I would like to use scrollbars instead. how do I do that?
当我使用一个包含大约 50 个项目的 html 选择框时,我会得到一个非常长的列表。我想改用滚动条。我怎么做?
回答by Khez
You need to use CSS, specifically height and overflow:
您需要使用 CSS,特别是高度和溢出:
CSS
CSS
.select{
height:100px;
overflow:scroll;
}
HTML
HTML
<select class="select"></select>
If you need anything more specific, ask!
如果您需要更具体的内容,请询问!
回答by devrooms
It is not possible to do this in HTML. See Height of an HTML select box (dropdown)
在 HTML 中无法做到这一点。请参阅HTML 选择框的高度(下拉列表)
There are other ways of achiving this though javascript or jQuery, with links on that page to some jQuery plugins which create a "fake" html select box that looks and behaves like one, but can have the height set.
还有其他方法可以通过 javascript 或 jQuery 实现这一点,在该页面上有一些 jQuery 插件的链接,这些插件创建了一个“假”的 html 选择框,它的外观和行为都像一个,但可以设置高度。
回答by Corneliu
It is not possible to set the number of visible items for a single value select box. There is a size attribute, but that will transform the dropdown into multiple selection list.
无法为单个值选择框设置可见项目的数量。有一个 size 属性,但这会将下拉列表转换为多选列表。