html - 字形高度与 select2 下拉列表不匹配

标签 html css jquery-select2 glyphicons

当我添加 select2 下拉菜单时,字形图标高度不一样 enter image description here

这是html代码

 <form class="well form-horizontal" action=" " method="post" id="user_edit">

  <div class="form-group">
        <label class="col-md-1 nopadding control-label"></label>
        <div class="col-md-8 nopadding inputGroupContainer">
            <div class="input-group field-width">

             <span class="input-group-addon" >
              <i class="fa fa-venus-mars" ></i></span>
               <select name="gender" id="gender" class="gender form-control 
     js-example-basic-single">
                    <option value="">Not Telling</option>
                    <option value="m">Male</option>
                    <option value="f">Female</option>
                </select>

            </div>
        </div>
    </div>
    </form>

js文件

$(document).ready(function() {
    $(".js-example-basic-single").select2();
});

我为 select2 添加的 css 文件

.glyphicon{
color:#007bcc;
 }
 .select2-selection__rendered{
 line-height: 32px!important;
 }
 [class^='select2'] {
 border-radius: 0px !important;
 }

 .select2-selection__arrow{
  height: 34px;!important;
  }
 .select2-container--default .select2-selection--single{
 background-color: #eeeeee !important;
 height: 34px!important;
 font-size: 15px;!important;
  margin-top: 0.5px!important;
 margin-left: -1px!important;

 }

当我将页面缩放超过 100% 时,高度相同。

最佳答案

.select2-container--default .select2-selection--single 中移除 margin-top: 0.5px!important;

$(document).ready(function() {
    $(".js-example-basic-single").select2();
});
.glyphicon{
color:#007bcc;
 }
 .select2-selection__rendered{
 line-height: 32px!important;
 }
 [class^='select2'] {
 border-radius: 0px !important;
 }

 .select2-selection__arrow{
  height: 34px;!important;
  }
 .select2-container--default .select2-selection--single{
 background-color: #eeeeee !important;
 height: 34px!important;
 font-size: 15px;!important;

 margin-left: -1px!important;

 }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
     <form class="well form-horizontal" action=" " method="post" id="user_edit">
  <div class="form-group">
        <label class="col-md-1 nopadding control-label"></label>
        <div class="col-md-8 nopadding inputGroupContainer">
            <div class="input-group field-width">
             <span class="input-group-addon" >
              <i class="fa fa-venus-mars" ></i></span>
               <select name="gender" id="gender" class="gender form-control 
     js-example-basic-single">
                    <option value="">Not Telling</option>
                    <option value="m">Male</option>
                    <option value="f">Female</option>
                </select>
            </div>
        </div>
    </div>
    </form>

关于html - 字形高度与 select2 下拉列表不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44896450/

相关文章:

javascript - 内容编辑器中的简单 Sharepoint 2013 JavaScript

javascript - 如何使用 jQuery 设置边框宽度?

javascript - 访问对象标签的外部 HTML 页面内容

jquery - Bootstrap 列未同步对齐

html - 如何让元素填充父级的 100% 高度

javascript - 改进我的可拖动 DIV

php - yii2 多重过滤器进入搜索模型

html - h1 标题上的链接使导入的网络字体大小加倍

ruby-on-rails - Select2 占位符在带有 hidden_​​field 的 Rails 应用程序中不起作用

javascript - 添加一个额外的自定义类到 select2-container