开发者

Horizontal scrollbar not working on select tag

I am trying to set the horizontal scrollbars on a select tag which is not working.

Here's the code:

  <select style="height: 250px; width: 300px; overflow: auto;" 
  id="dnn_ctr459_ManageRelatedProducts_lstFrom" multiple="multiple"   
  name="dnn$ctr459$ManageRelatedProducts$lstFrom" class="selectList" size="4">
   开发者_运维问答  <option value="9">33 Uithoeke</option>
     <option value="10">Aantekeninge by Koos Prinsloo</option>
     <option value="11">Aantekeninge by Koos Prinsloo (enhanced e-book)</option>
     <option value="12">Access to Social Security</option>
     <option value="13">Angling for Interpretation</option>
  </select>

.selectList 
{
   height: 250px;
   overflow: auto;
   width: 300px;
}

Horizontal scrollbar not working on select tag

Matt's solution results in this:

Horizontal scrollbar not working on select tag

Final result in FF

Horizontal scrollbar not working on select tag

Final result in IE, thanks to Matt!

Horizontal scrollbar not working on select tag


Not sure if you can do that, but you can always trick it into looking like that by placing a div around the select, and setting the width and horizontal scroll on that. Taken from here.


You cannot force scrollbars on select elements.


Yes, you can. Try it with JQuery:

<div id='test' style="overflow-x:scroll; width:120px; overflow: -moz-scrollbars-horizontal;">
<select id='mySelect' name="mySelect" size="5">
    <option value="1">one two three four five six</option>
    <option value="2">seven eight</option>
    <option value="3">nine ten</option>
    <option value="1">one two three four five six</option>
    <option value="2">seven eight</option>
    <option value="3">nine ten</option>
    <option value="1">one two three four five six</option>
    <option value="2">seven eight</option>
    <option value="3">nine ten</option>
    <option value="1">one two three four five six</option>
    <option value="2">seven eight</option>
    <option value="3">nine ten</option>
</select>
<div id="divv" style='font-size: 1px'>&nbsp</div>
</div>

<script>
    $('#divv').css('width', $('#mySelect').outerWidth());
    $('#mySelect').css('width', $('#test').outerWidth());
    $( "#test" ).scroll(function() {
        $('#mySelect').css('width', $(this).outerWidth() + $(this).scrollLeft());
    });
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜