Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 3 alertCtrl custom cssClass not working

I followed the official documentation and my code is like below:

let alert = this.alertCtrl.create({
  title: 'Alert',
  subTitle: 'Subtitle',
  message: 'This is an alert message.',
  buttons: ['OK'],
  cssClass: 'profalert'
});

alert.present();

and my CSS:

.profalert{
    color:#e7333c;
    background-color: red;

}

But this is not changing the alertbox color. I also tried alert .setCssClass('profalert');

I already checked this

like image 316
Arijit Avatar asked Nov 25 '17 02:11

Arijit


Video Answer


2 Answers

It is working fine.You just need to declare it inside the app.scss file.

app.scss

.profalert{
    color:#e7333c;
    background-color: red;

}

Result:

When I applied your style to my app's alert box:

enter image description here

like image 107
Sampath Avatar answered Oct 05 '22 14:10

Sampath


If you're working with Ionic 4 then add:

.profalert{
color:#e7333c;
background-color: red;
}

to global.scss

If interested in horizontal alignment of alert control buttons, check my answer here

If you're migrating from older versions to ionic 4.x, check out this repo for breaking changes.

like image 28
7guyo Avatar answered Oct 05 '22 16:10

7guyo