HTML Select a tag showing vertical scrolling with parameter 10

I want to make a selection box like this

enter image description here

with option 10 of the selection, when I try to add more than 15 options, it shows the vertical scroll bar, but not show when it has 10 options.

is there any way to achieve this.

+4
source share
3 answers

apply size="10"to your choice.

sort of:

<select size="10">
   // all your options
</select>

You have to put some style in the shortcut like border, background image, etc.

Something like that:

<label id='choose' for='options'>Select options</label>
<br clear='all' />
<select id='options' size="10" style='display:none;'>
    // all the options
</select>

then use this jQuery code:

$('#choose').click(function(){
    $(this).siblings('select').toggle();
});

Demo script


Try the following:

$('#choose').click(function (e) {
    e.stopPropagation();
    $(this).siblings('select').css('width', $(this).outerWidth(true)).toggle();
});

$('#options').change(function (e) {
    e.stopPropagation();
    var val = this.value || 'Select options';
    $(this).siblings('#choose').text(val);
    $(this).hide();
});

How did you comment:

1 , , css: , FF, .

:

$('#options').find('option').on({
    mouseover: function () {
        $('.hover').removeClass('hover');
        $(this).addClass('hover');
    },
    mouseleave: function () {
        $(this).removeClass('hover');
    }
});

hover.

+5

. size 1, , , , , .

<select size="10">..</select>

0
source

Source: https://habr.com/ru/post/1543856/


All Articles