一种方式做到这一点可能是使用一个div来掩盖滚动条。只需添加一个与其容器具有相同背景色的div,并将其放置在滚动条的顶部。我建议使用JavaScript或最好是jQuery来定位div,并记住使这两个元素重叠;这可以通过将它们的两个位置设置为绝对值(以及它们的容器的相对位置)来完成。
下面是一个简单的例子:
https://jsfiddle.net/jffe4sy3/1/
这不是很漂亮或非常通用,但它在大多数情况下工作。
HTML:
<select id="select_id" class="select" size="5">
<option value="1" >test1</option>
<option value="2" >test2</option>
<option value="3" SELECTED>test3</option>
<option value="4" >test4</option>
<option value="5" >test5</option>
</select>
<div id="div_id" class="cover"></div>
CSS:
.select{
height:60px; //set this to your max-height (i.e. max-height:400px;)
position:absolute;
}
.cover {
background-color:white;
position:absolute;
border-left:solid grey 1px;
width:16px;
}
的JavaScript/jQuery的:
$("#div_id").height($("#select_id").height()+2); // the height of the select + 2px to include the border
$("#div_id").css("margin-left", $("#select_id").width()-15); // the width of the select minus the scrollbar
不过我建议你总是在适用时使用display:none
选择!您应该只在极少数情况下使用此解决方案。
事情是这样的:http://stackoverflow.com/questions/4531269/hide-vertical-scrollbar-in-select-element? –
我已经尝试这样做,但无法取得成功。有没有其他的方法来解决这个bug? – SPG
用firefox的开发工具(F12)来检查它 –