jQuery select2 更改背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17771824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
select2 change background color
提问by Patrick Jane
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 ?
我正在尝试在我创建的网页上使用 select2。但是组合框背景似乎是透明的,但我需要将其更改为另一种颜色。我尝试修改select2.css
文件,但似乎没有任何效果。有任何想法吗 ?
回答by Matthew R.
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!
希望这可以帮助!
回答by Grandor
It's a little late to help the OP, but I'll leave this answer in the hope it might help somebody.
帮助OP有点晚了,但我会留下这个答案,希望它可以帮助某人。
I don't know about other versions, but using select2-rails 3.5.9.3 (which according to their github pagemeans the version of select2 being used is 3.5) I was only able to change the background color as follows:
我不知道其他版本,但使用 select2-rails 3.5.9.3(根据他们的github 页面意味着正在使用的 select2 版本是 3.5)我只能按如下方式更改背景颜色:
.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.
无论如何,我没有尝试使用“vanilla select2”,所以我不知道这种情况是否有什么不同。
回答by Rana Hyder
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;
}