how to give Alert Controller css in ionic 4?

你离开我真会死。 提交于 2019-12-11 00:49:19

问题


I want to give alert controller style in ionic 4.these is my demo code,

async presentalert() {
    const alert = await this.alertCtrl.create({
      header: '  DO YOU WANT TO CANCEL',
      message: 'DO YOU WANT TO CANCEL',
      cssClass: 'alertCancel',
      mode: 'ios',
      buttons: [
        {
          text: 'NO',
          role: 'cancel',
          cssClass: 'alertButton',
          handler: () => {
            console.log('Confirm Cancel');
          }
        }, {
          text: 'YES',
          cssClass: 'alertButton',
          handler: () => {
            console.log('Confirm Okay');
          }
        }
      ]
    })
    await alert.present();
  }

and i tried to apply scss in global.scss

 .alertCancel{
    --background: red;
  }
  .alertButton {
     background-color: white !important;
  }

I have tried every possible way to give css in alert controller but it s not working so please help me I am stuck here.


回答1:


--background is a css variable of the component ion-alert, therefore do the following in the variables.scss

ion-alert
{
 --background: red !important;
}

For reference:

https://ionicframework.com/docs/theming/css-variables#ionic-variables

https://petercoding.com/2019/04/25/theming-your-app-in-ionic4/#css-custom-properties



来源:https://stackoverflow.com/questions/55687695/how-to-give-alert-controller-css-in-ionic-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!