How to add a specific class to select2 drop element?

后端 未结 4 2428
再見小時候
再見小時候 2021-02-18 18:23

I have select2 customized via css with its general classes and ids.

Now, I\'m trying to customize a specific class that will be provided to select2 and then apply in css

4条回答
  •  没有蜡笔的小新
    2021-02-18 18:45

    It will depend on the version of select2 that you are using. The html structure changed in one of the versions.

    Here is Fiddle example: https://jsfiddle.net/LpjcqbLu/

    I just put the 'error' class on the select box.

    .error + .select2-container, 
    .error + .select2-container + .select2-container .select2-dropdown {
        border: 3px solid red !important;
    }
    

    In earlier versions, the dropdown was not close to the select box (in the dom), so you would have to do a javascript solution to apply the error class directly.

提交回复
热议问题