Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select2 change background color

I am trying to use select2 on a webpage I am creating. However the combobox background seems to be transparent but I need to change it to another color. I tried modifying the select2.css file but nothing seems to work. Any Ideas ?

like image 248
Patrick Jane Avatar asked Jul 21 '13 11:07

Patrick Jane


People also ask

What select2 dropdown?

By default, Select2 will attach the dropdown to the end of the body and will absolutely position it to appear above or below the selection container. Select2 will display the dropdown above the container if there is not enough space below the container, but there is enough space above it.

How to disable select2 dropdown using jquery?

Disabling a Select2 controlSelect2 will respond to the disabled attribute on <select> elements. You can also initialize Select2 with disabled: true to get the same effect.


3 Answers

If you are trying to target the combo box wrapper use

.select2-search { background-color: #00f; }

If you are trying to target the input use

.select2-search input { background-color: #00f; }

And if you are trying to target the results wrapper use

.select2-results { background-color: #00f; }

Hope this helps!

like image 142
Matthew R. Avatar answered Nov 10 '22 23:11

Matthew R.


It's a little late to help the OP, but I'll leave this answer in the hope it might help somebody.

I don't know about other versions, but using select2-rails 3.5.9.3 (which according to their github page means the version of select2 being used is 3.5) I was only able to change the background color as follows:

.select2-choice { background-color: #00f !important; }

The selector mentioned by Matthew for the results works, though.

Anyway, I didn't try it using "vanilla select2," so I don't know if there is any difference in this case.

like image 42
Grandor Avatar answered Nov 11 '22 01:11

Grandor


For combo box

.select2-container--default .select2-selection--single{
    background-color: #000;
}

For options search box

.select2-search--dropdown{
    background-color: #000;
}
.select2-search__field{
    background-color: #000;
}

and for options list

.select2-results { 
    background-color: #000;
}
like image 2
Rana Hyder Avatar answered Nov 10 '22 23:11

Rana Hyder