Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly style the Select2 outline on :focus?

I'm using Select2 to style my <select> boxes, but I can't seem to style the forced outline which Chrome applies to the style:

Problem: enter image description here

I've tried several lines of (very unprofessionally, !important) CSS code, but so far I haven't come up with the solution, this is what i'm at right now:

CSS:

.select2 > *:focus, .select2:focus .select2 > *, .select2 {
    outline-width: 0px !important;
}

For the sake of excluding potential problems, i'm definitely including this CSS file, after my regular select2.css

Also, a fiddle would be problematic, but I could provide one if really necessary

like image 973
roberrrt-s Avatar asked Sep 02 '16 13:09

roberrrt-s


People also ask

How do you focus Select 2?

$('#id'). select2('open'); will set focus and open the select2 ready for search. $('#id'). select2('focus'); will set the focus on select2 but not select2 will be not opened for search.

How do I change the select2 arrow?

Even above in Shadows answer, you have to specify each select2 element to have the dropdown parent. So when the dropdown opens, select2-container--open is attached to the dropdown, the select2-selection__arrow will receive the transform css.

How do I change the height of my Select 2?

Adding the following is enough: . select2-container . select2-choice { height: 200px; } To have it apply only after an object is selected, add/modify the corresponding css on a change event or similar. This changes the height of the select2 input field, which is not what was asked for.


2 Answers

This seems to do the trick:

  <style>
    .select2-container *:focus {
        outline: none;
    }
  </style>

Here is a plunk.

like image 65
Dave Avatar answered Nov 14 '22 20:11

Dave


This works for me:

&.select2-container--focus {
    outline: none;
}
like image 28
Maranda P. Avatar answered Nov 14 '22 20:11

Maranda P.