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

4

8

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?

Sparteine answered 12/8, 2016 at 14:43 Comment(1)
You could probably use css to do that, but there is no code example in the question so idkDippy
N
10

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;
}
Ne answered 12/8, 2016 at 15:53 Comment(0)
D
3
.select2-selection__choice__remove {
    float: right;
    margin-left: 5px /* I added to separate a little bit */
}

enter image description here

Derouen answered 7/9, 2019 at 16:48 Comment(0)
R
2

You can move the x using CSS only by adding in your css-File some code like this:

  .select2-container-multi .select2-search-choice-close {
    left: auto;
    right: 3px;
  }

  .select2-container-multi .select2-choices .select2-search-choice {
    padding-right: 18px;
    padding-left: 5px;
  }
Recurvate answered 1/3, 2019 at 10:8 Comment(0)
T
0

in version 4.1.0

.select2-selection__choice {
     flex-direction: row-reverse!important;
}
Tetracaine answered 6/9, 2023 at 20:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.