首页 > 解决方案 > ng-select - 改变高度

问题描述

我在 Angular 5 版本 1.4.2 中使用 ng-select 库https://github.com/ng-select/。我想对其进行自定义,以使 ng-select 的高度更小。如何做到这一点?我在https://github.com/ng-select/ng-select#custom-styles上查看了使用样式进行自定义,但无法使其正常工作。

我添加了一个定制的 CCS 来尝试执行此操作。

这是我的 ng-select 代码

                <label class="col-sm-4 text-sm-right col-form-label">Payout Format</label>
                <div class="col-sm-8">
                    <ng-select
                        [items]="payoutFormats"
                        [closeOnSelect]="true"
                        [searchable]="true"
                        bindValue="payoutBatchFormatID"
                        bindLabel="name"
                        placeholder="All"
                        [(ngModel)]="filter.payoutFormats"
                        name="payoutFormat"
                        class="custom">
                    </ng-select>
                </div>

这是我为自定义它而添加的 CSS:

.ng-select.custom {
    height:5px;
    font-size: 0.8em;
}

.ng-select.custom .ng-select-container  {
    height:5px;
}

可以看出,我尝试在 2 个地方设置高度,但没有效果。我能够成功更改字体大小。

这是我的选择在 CSS 之后的样子: 在此处输入图像描述

我需要它更小。

标签: angularangular-ngselect

解决方案


通过 CSS 覆盖样式:

.ng-select .ng-select-container {
  min-height: 20px;
}

.ng-select.ng-select-single .ng-select-container {
  height: 20px;
}

ng-选择


推荐阅读