How do you set the max height of an expanded “Chosen” element (jQuery plugin)

本小妞迷上赌 提交于 2019-11-30 17:40:52
Miguel

tl;dr: Add this CSS rule to your styles.css:

.chosen-container .chosen-results {
    max-height:100px;
}


Initially I didn't understand this, but this selector is actually applying to classes inside the Chosen (the library generates its own html elements that are seperate from the <select> element) They aren't referring to the container that you, the designer, have put the Chosen in, so they will work in any situation.

However even when I realised that, this selector wouldn't work as chosen.css has the exact same selector, and because the last declared rule wins, my rule had no effect. There are two solutions to this:

  • Add !important to your custom rule (probably the incorrect way)

OR

  • Make sure your styles.css is declared after chosen.css. My links were in this order:

    <link rel="stylesheet" href="css/main.css">

    <link rel="stylesheet" href="chosen/chosen.css">

    If you change the order so that your main.css (or whatever you've called your custom styles file) is declared after, the problem will also be solved.

Miguel's answer didn't work out for me, but instead this did:

.dropdown-menu {
    max-height:250px !important;
    overflow-y: scroll;
}

I solved this issue by the following way.

.chosen-container .chosen-results {
    color: #444;
    position: relative;
    overflow-x: hidden;
    overflow-y: auto;
    margin: 0 4px 4px 0;
    padding: 0 0 0 4px;
    max-height: 240px;
   -webkit-overflow-scrolling: touch;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!