Add custom styling to ion-select

Viewed 18960

I have a ion-select with few options i gave a header using [selectOptions], is there a way to define a css so that i could able to set background-color to header, button alignment ,and add a icon to the header

 <ion-select [selectOptions]="daysOptions" #selectDays="ngModel" required name="selectedDay" [(ngModel)]="selectDay" >
         <ion-option *ngFor="let day of Days;" [value]="day.val">{{day.name}}</ion-option>
 </ion-select>

could someone help me

3 Answers

You can fix this easily now

Add to ion-select element:

[interfaceOptions]="{cssClass: 'my-class'}"

Add to css:

.my-class .alert-wrapper {
    max-width: 94% !important;
}

I needed a color selector couple of months ago but I couldn’t find any. The only way to do this was using custom CSS. I tried adding CSS classes to ion-select and ion-option but the classes doesn’t get reflected in the generated output. So the only way to apply the custom CSS to ion-select and ion-options is by using the parent element and some JS.

You can check the logic in: HTML: https://github.com/ketanyekale/ionic-color-and-image-selector/blob/master/src/pages/home/home.html

TS: https://github.com/ketanyekale/ionic-color-and-image-selector/blob/master/src/pages/home/home.ts

SCSS: https://github.com/ketanyekale/ionic-color-and-image-selector/blob/master/src/pages/home/home.scss

Related