ng-select - Change height
Asked Answered
F

4

14

I am using the ng-select library https://github.com/ng-select/ for Angular 5 at version 1.4.2. I want to customize it so the height of the ng-select is smaller. How can this be achieved? I have had a look at customizing with styles at https://github.com/ng-select/ng-select#custom-styles but cannot get it to work.

I have added a customized CCS with an attempt to do this.

Here is my code of the 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>

Here is the CSS I have added to customize it:

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

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

As can be seen, I have tried setting the height in 2 places but it has no effect. I was able to change the font size successfully.

Here is how my select looks like after the CSS: enter image description here

I need it to be smaller.

Fuddle answered 7/6, 2019 at 12:8 Comment(0)
M
20

Override the styles through CSS:

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

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

ng-select

Modern answered 7/6, 2019 at 12:17 Comment(4)
Thanks that worked. How can I use it with my custom class? The reason because I only want to apply this styling just to this page.Fuddle
@Fuddle if you want to apply for just one page, then apply to the CSS of the page/ component only.Modern
Which style needs to be overridden for a multi select box? I have added the attribute [multiple]="true" and the style .ng-select-multiple .ng-select-container but the box is staying 1 size with the applied styles.Fuddle
Note that currently there is a defect (I think) in ng-select using this. When you open the select for the first time, the "arrow" moves vertically a bunch of pixels and looks wrong. I opened github.com/ng-select/ng-select/issues/2145 to address it. Included in there is a stackblitz with a workaround. You can also see how to apply height changes to mulit-select.Gulf
H
2

Use this one:

::ng-deep .ng-select-container {
  height: 5px !important;
  font-size: 0.8em!important;
}
Hortensehortensia answered 2/6, 2021 at 10:23 Comment(1)
This worked for me whereas the accepted answer did not.Helvetii
G
1

in your style add this:

::ng-deep .ng-select .ng-select-container , ::ng-deep .ng-select.ng-select-single .ng-select-container{
  min-height: 5px;
  font-size: 0.8em;
}
Glazier answered 5/11, 2021 at 10:35 Comment(0)
E
0

The solution of alirezacode worked only for multi-select dropdowns. Not for single selects. This works for both:

::ng-deep .ng-select .ng-select-container,
::ng-deep .ng-select.ng-select-single .ng-select-container {
  min-height: 5px;
  font-size: 0.8em;
}

::ng-deep .ng-select.ng-select-single .ng-select-container {
  height: 26px !important;
  font-size: 0.8em !important;
}
Evonevonne answered 3/2 at 21:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.