html - 选择元素下拉列表的最大高度(选项元素)

标签 html css

我如何限制选择元素的下拉列表的高度 - 这样如果选项的总数大于此高度 - 我应该在下拉列表中滚动。 如果我能在像素或元素数量方面做到这一点,我会很满意。

假设我有以下 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/

相关文章:

html - 双类不工作

javascript - 使用 javascript(不是 php)将 <br> 变成换行符

html - 在 jquery-mobile 中,如何以编程方式添加具有所有 css 的页面元素?

html - Flex - 具有相同高度的并排子容器

html - Angular 2 Material 自定义 md-menu

html - 为悬停图像添加半右边框

html - 表格单元格中宽度为 100% 的按钮会阻止 Firefox 中单元格的自动宽度

javascript - 如何用 JSS 覆盖类

html - 嵌套 <span> 在 <p> 标签内,提供不同的字体大小

javascript - 使用 JavaScript 切换联系表单字段