6
votes

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
You mean the alert itself? [selectOptions] has an option called cssClass that will let you pass a class on to the alert. If you want to make your own custom component its really not that hard, here is an example for a select without ok/cancel: github.com/misha130/ionic2-select-nobuttons/blob/master/src/… - misha130

3 Answers

4
votes

Yes, you can use cssClass in option like this:

// In your component
daysOptions = {
    cssClass: 'my-class',
    ...,
}

Then in css you can do what you want eg:

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

Thank's to ionic docs: https://ionicframework.com/docs/api/components/alert/AlertController/#advanced

3
votes

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;
}
1
votes

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