HTML选择多个:显示所有元素

时间:2015-07-03 13:59:36

标签: html listbox

如何使列表框足够高以适应所有选项(最好隐藏滚动条)?

设置大小等于长度,但如果长度是动态的,那么这是一种简单的方法吗?

1 个答案:

答案 0 :(得分:0)

因此,您无法仅使用选择标记隐藏滚动条。你需要添加一个div来覆盖它

HTML:

<div class="opt">
  <select multiple='multiple'size=11>
    <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>
</div>

的CSS:

.opt { 
  display:inline-block; 
  vertical-align:top; 
  overflow:hidden; 
  border:solid grey 1px;
}
.opt select { 
  padding:10px; 
  margin:-5px -20px -5px -5px; 
}

https://jsfiddle.net/KingPyrox/eoLdr4pc/