如何应用离子2吐司的cssClass

时间:2017-03-10 06:46:36

标签: css angular sass ionic2 toast

我跟着这个link来为我的吐司申请cssClass。

我的html中有按钮

<button ion-button (click)="presentToast()"> toast</button>

这是我的.ts文件

presentToast() {
    let toast = this.toastCtrl.create({
      message: "Press again to exit",
      cssClass: "bottomToast",
      position: 'bottom'
    });

    toast.onDidDismiss(() => {
      console.log('Dismissed toast');
    });

    toast.present();
  }

这是我的app.css文件

.bottomToast{
    .toast-md .toast-wrapper {
        position: absolute;
        right: 0;
        left: 0;
        z-index: 10;
        display: block;
        margin: auto;
        width: 40%;
        max-width: 700px;
        border-radius: 35px;
        background: gray;
        /* color: black; */
    }

    .toast-md .toast-message {
        padding: 19px 16px 17px;
        font-size: 1.5rem;
        /* color: #fff; */
        text-align: center;
    }
}

我在吐司上的检查元素我得到了这个

<ion-toast role="dialog" class="toast-md bottomToast" aria-labelledby="toast-hdr-0" style="z-index: 19999;"><div class="toast-wrapper toast-bottom" style="transform: translateY(0%);"> <div class="toast-container"> <!--template bindings={ "ng-reflect-ng-if": "Press again to exit" }--><div class="toast-message" ng-reflect-id="toast-hdr-0" id="toast-hdr-0">Press again to exit</div> <!--template bindings={ "ng-reflect-ng-if": null }--> </div> </div></ion-toast>

当我删除.bottomToast并仅提供.toast-md .toast-wrapper.toast-md .toast-message时,它工作正常

  

我希望toast css在bottomToast课程内部,我已经做了什么

1 个答案:

答案 0 :(得分:1)

您的bottomToast不是toast-md的父母。试试:

ion-toast.bottomToast.toast-md {
    .toast-wrapper.toast-bottom  {
        position: absolute;
        right: 0;
        left: 0;
        z-index: 10;
        display: block;
        margin: auto;
        width: 40%;
        max-width: 700px;
        border-radius: 35px;
        background: gray;
        /* color: black; */
    }

    .toast-md .toast-message {
    padding: 19px 16px 17px;
    font-size: 1.5rem;
    /* color: #fff; */
    text-align: center;
}
div#toast-hdr-0 {
    text-align: center;
}
}