Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select2 - How to move the close icon to the right of the selected item

I am using select2 for displaying a multiple selection component. Instead of showing the close icon(x) to the left of the item, how can I move it to the right of the selected item?

like image 286
It'sMe Avatar asked Aug 12 '16 14:08

It'sMe


People also ask

How do I stop select2 from auto selecting the first option?

Your best option is to use the placeholder support in Select2 and include a blank option tag as your default selection.

What does select2 () do?

Select2 gives you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options.


2 Answers

If you add float: right; to the .select2-selection__choice__remove css class, this will set it on the right side.

EDIT: If you don't want to touch the select2 stylesheets, you can always use jquery and do something like this:

$('.select2').on('select2:open', function () {
  $('.select2-selection__choice__remove').addClass('select2-remove-right');
});

.select2-remove-right {
  float: right;
}
like image 124
Mathieu Avatar answered Sep 18 '22 17:09

Mathieu


.select2-selection__choice__remove {
    float: right;
    margin-left: 5px /* I added to separate a little bit */
}

enter image description here

like image 42
Hector Lara Avatar answered Sep 17 '22 17:09

Hector Lara