Limit Initial width of select list

前端 未结 6 1124
春和景丽
春和景丽 2021-01-12 20:17

I have a select list, where some clients have entered insanely long options for them, which breaks the design. I\'m wondering if there is a way to set a fixed width on the s

6条回答
  •  太阳男子
    2021-01-12 20:52

    If the list you have (the entries in list, but a custom list built with, say a

    .

    This is not difficult, all you need is

    a div that contains the default option,
    a hidden div with all the options
    When the user clicks the default option show the hidden div
    On click of the items in the hidden div (that is now visible) make that the selected item in the first div

    Perhaps there already jquery plugin for this. but i am not sure whether you are open to jquery, I am not a jquery expert anyway.

    I know this comparitively more effort than having a select, but i think it is worth the effort. All the hacks - expand the div onmouseover, onclick etc do not look great, might still break your design, and depending on the amount of data the user can enter, would still not be effective.

    In the custom list approach, you can wrap the elements, so that you are in complete control.

提交回复
热议问题