我如何限制选择元素的下拉列表的高度 - 这样如果选项的总数大于此高度 - 我应该在下拉列表中滚动。 如果我能在像素或元素数量方面做到这一点,我会很满意。
假设我有以下 html 标记:
<select>
<option selected>Select</option>
<option>This is an option</option>
<option>This is another Option</option>
<option>This is another Option</option>
<option>This is another Option</option>
<option>This is another Option</option>
<option>This is another Option</option>
<option>This is another Option</option>
<option>This is another Option</option>
<option>This is another Option</option>
<option>This is another Option</option>
</select>
我如何在滚动中只显示前 4 个选项和其余选项。
This是我目前所拥有的,但没有用。
最佳答案
在 StackOverflow 上四处搜索,我遇到了 this .可悲的是,如果你想让它成为一个下拉框,你无法在 CSS 中实现你想要的。如链接中所述,JavaScript 或 jQuery 可以解决问题,或者您可以在 select
标记上使用 size
属性,但这会破坏下拉框的外观。
关于html - 选择元素下拉列表的最大高度(选项元素),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13362484/