Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we customize ionic toast close button.?

I am trying to add background color for ionic toast button but couldn't succeed. I tried below css in global.scss. Could someone tell me how can I achieve this.?

  .positive-toast-message {
       --min-width: 60%;
       --background: #bde7c3;
       --color: black;
       --button-color: black;
       .toast-button {
        --background: red !important;
        background: white !important;
        background-color: blue !important;
       }
   }

Once Toast is created, it is applying 'positive-toast-message' css properly

like image 828
Deepak Avatar asked May 24 '26 22:05

Deepak


2 Answers

If you want to do that, then you should use css class. Call the toast like this

const toast = await this.toastCtrl.create({
    message: 'Please Fill all fields',
    duration: 30000,
    position: 'top',
    cssClass: 'toast-bg'
  });

  toast.present();

Then go to global.scss file and put this class there

.toast-bg {
  --background: blue;
  --button-color: #ffffff;
}

This should work. change the color to whatever color you want within the css class in global.scss

like image 145
Praise Hart Avatar answered May 26 '26 12:05

Praise Hart


On IONIC 5 you can simply use CSS shadow and toast part to apply your customization.

for example, in order to change the button's color you can simply use the below code:

ion-toast::part(button) {
  --button-color: var(--ion-color-tertiary) !important;
  --color: var(--ion-color-tertiary) !important;
}
like image 23
user2642051 Avatar answered May 26 '26 13:05

user2642051



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!