CSS 如何更改 Bootstrap 3 所选选项的背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24346956/
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
How to Change Bootstrap 3 Selected Option Background Color
提问by user3649067
Can you please take a look at This Demoand let me know how I can change the background color of the selected option from Blue to some other colors?
你能看看这个演示,让我知道如何将所选选项的背景颜色从蓝色更改为其他颜色吗?
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
Thanks
谢谢
回答by imbondbaby
Take a look at this:
看看这个:
select{
background: yellow !important;
color:#FFF;
text-shadow:0 1px 0 rgba(0,0,0,0.4);
}
option:not(:checked) {
background-color: white;
color:#000;
}
Use !important
to override the Bootstrap CSS.
使用!important
覆盖引导CSS。
!important
is a useful tool, but the drawback is that it's kind of a tool of last resort. So you don't want to over-use it as you'll end up causing headaches down the road for anyone that's maintaining the site.
!important
是一个有用的工具,但缺点是它是一种不得已的工具。所以你不想过度使用它,因为你最终会给维护网站的任何人带来麻烦。