简体   繁体   English

如何更改Bootstrap 3选定的选项背景颜色

[英]How to Change Bootstrap 3 Selected Option Background Color

Can you please take a look at This Demo and 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 谢谢

Take a look at this: 看看这个:

http://jsfiddle.net/xL4Gu/3/ http://jsfiddle.net/xL4Gu/3/

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来覆盖Bootstrap CSS。

!important is a useful tool, but the drawback is that it's kind of a tool of last resort. !important是一个有用的工具,但缺点是它是一种最后的工具。 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. 因此,您不希望过度使用它,因为您最终会为维护网站的任何人造成头痛。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM