Is it possible to limit the height of a selectmenu

2019-03-04 00:16发布

问题:

I've been trying to do this by setting the size attribute of the source select element, but it's being ignored. There doesn't seem to any height setting option for the widget. Is it possible?

The widget is currently working inside a div dialog that has overflow hidden, so the drop-down (26 items, always) just disappears off the div.

回答1:

There is no size similar option in jQuery UI Selectmenu (aka show more than just a button but a select "pane"). But it's possible to change the height of the generated button by CSS.

Another idea would be changing the rendering mechanism like @Michael proposed.

A demo fiddle would be useful. When your actual issue is the overflow of the div you could try to add the menu to another element by using the appendTo option, see http://api.jqueryui.com/selectmenu/#option-appendTo



回答2:

How about some css...

.ui-selectmenu-open{
        max-height: 350px;
        overflow-y: scroll;
    }