How to customize jquery select2 plugin - jQuery replacement for individual blocks

I am looking for a way to customize the appearance of Select2 in a project. Looked through the documentation but couldn't find any specific instructions on how to change the style of the select box.

Please see the image below circled in red is a replacement for select2 for selection. I would like to change the border style and make it look like other text boxes on the page.

NB: I am using AngularJs and created a directive for select2 link like so:

...

directive('select2', function () {
        return {
            restrict: 'A',
            require: 'ngModel',
            link: function (scope, element, attrs, ngModelCtrl) {
                element.select2({
                    allowClear: true,
                    width: 'resolve'
                });
            }
        };
    });

      

Here is the HTML code:

<select select2 class="form-control" ng-model="select2" style="width:100%;">
                <option value="one">First</option>
                <option value="two">Second</option>
                <option value="three">Third</option>
            </select>

      

enter image description here

+3


source to share


1 answer


My guess is that one can simply overwrite the existing CSS rules.



.select2-container--default .select2-selection--single {
  background-color: #fff;
  border: 1px solid #aaa; //change the border here
  border-radius: 4px;
}

      

+1


source







All Articles