Make multiple-select to adjust its height to fit options without scroll bar

前端 未结 16 1092
说谎
说谎 2020-12-24 03:59

Apparently this doesn\'t work:

   select[multiple]{
     height: 100%;
   }

it makes the select have 100% page height...

auto

16条回答
  •  佛祖请我去吃肉
    2020-12-24 04:57

    You can only do this in Javascript/JQuery, you can do it with the following JQuery (assuming you've gave your select an id of multiselect):

    $(function () {
        $("#multiSelect").css("height", parseInt($("#multiSelect option").length) * 20);
    });
    

    Demo: http://jsfiddle.net/AZEFU/

提交回复
热议问题