设置bootstrap的selectpicker版本样式选择

时间:2016-12-04 15:56:43

标签: css twitter-bootstrap

我正在尝试并且失败,为boostrap-select小部件设置样式。我尝试了以下代码,但它不会更改selectpicker选择框中的背景和文本颜色:

 <select id="what" class="wia-filter-value selectpicker show-tick">
     <option selected>All</option>
     <option>Events</option>
     <option>Man Made</option>
     <option>Nature</option>
 </select>

我的CSS看起来像这样:

select {
    width: 200px;
    height: 30px;
    background-color: #141414 !important;
    border-style: solid;
    border-left-width: 3px;
    border-left-color: #00DDDD;
    border-top: none;
    border-bottom: none;
    border-right: none;
    color: white;
    font-size: 18px;
    font-weight: 200;
    padding-left: 6px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
.selectpicker{
    width: 200px;
    height: 30px;
    background-color: #141414 !important;
    border-style: solid;
    border-left-width: 3px;
    border-left-color: #00DDDD;
    border-top: none;
    border-bottom: none;
    border-right: none;
    color: white;
    font-size: 18px;
    font-weight: 200;
    padding-left: 6px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
select::-ms-expand { /* for IE 11 */
    display: none;
}
.wia-filter-value {
    width: 200px;
    height: 30px;
    background-color: #141414 !important;
    border-style: solid;
    border-left-width: 3px;
    border-left-color: #00DDDD;
    border-top: none;
    border-bottom: none;
    border-right: none;
    color: white;
    font-size: 18px;
    font-weight: 200;
    padding-left: 6px;
}

此CSS成功应用左边框颜色,但不应用背景颜色或文本颜色。

注意:enter link description here的stackoverflow中显示的解决方案是针对标准Boostrap选择的。我正在使用https://silviomoreto.github.io/bootstrap-select中的selectpicker小部件。该解决方案似乎不适用于selectpicker,或者至少我无法使其工作。

2 个答案:

答案 0 :(得分:3)

您需要定位插件正在应用的 Bootstrap-select 类。如果你检查元素,你可以看到发生了什么。这是一个屏幕截图,可供参考。

enter image description here

工作示例:

&#13;
&#13;
body {
  padding-top: 50px;
}
.bootstrap-select {
  max-width: 200px;
}
.bootstrap-select .btn {
  background-color: #141414;
  border-style: solid;
  border-left-width: 3px;
  border-left-color: #00DDDD;
  border-top: none;
  border-bottom: none;
  border-right: none;
  color: white;
  font-weight: 200;
  padding: 12px 12px;
  font-size: 16px;
  margin-bottom: 10px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}
.bootstrap-select .dropdown-menu {
  margin: 15px 0 0;
}
select::-ms-expand {
  /* for IE 11 */
  display: none;
}
&#13;
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css" rel="stylesheet" />

<div class="container text-center">

  <select id="what" class="form-control selectpicker show-tick">
    <option selected>All</option>
    <option>Events</option>
    <option>Man Made</option>
    <option>Nature</option>
  </select>

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
&#13;
&#13;
&#13;

答案 1 :(得分:-1)

<div class="form-group">
    <label class="control-label col-md-4">Theme White</label>
    <div class="col-md-8">
        <select class="form-control selectpicker" data-size="10" data-live-search="true" data-style="btn-white">
            <option value="" selected>Select a Country</option>
            <option value="AF">Afghanistan</option>
            <option value="AL">Albania</option>
            <option value="DZ">Algeria</option>
            <option value="AS">American Samoa</option>
            <option value="AD">Andorra</option>
            <option value="AO">Angola</option>
            <option value="AI">Anguilla</option>
            <option value="AQ">Antarctica</option>
            <option value="AG">Antigua and Barbuda</option>
        </select>
    </div>
</div>

添加data-style="btn-white"以获得白色