一種方式做到這一點可能是使用一個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)來檢查它 –