Ionic 3 - I want a modal screen not full size
Asked Answered
A

5

8

I need a modal page with no full size (80% width, <60% height, centered) to select some items, like an alert control. How to implement the CSS for this case?

Armadillo answered 9/3, 2018 at 2:23 Comment(0)
O
21

Initialize modal with cssClass

 let modal = this.modalCtrl.create(CustomSelectPage, {data: data}, {cssClass: 'select-modal' });

Then add CSS to the class in app.scss

.select-modal {
   background: rgba(0, 0, 0, 0.5) !important;
   padding: 20% 10%  !important;
}

Change the numbers according to your design.

Othelia answered 9/3, 2018 at 9:2 Comment(2)
Great, worked fine. There is a way to round corners, like link ?Armadillo
I wanted that rounded effect as well. I did the following: .text-properties-modal { background: rgba(0, 0, 0, 0.5) !important; padding: 20% 10% !important; .modal-wrapper { border-radius: 20px; } }Hi
C
1

put this code only in your component css file

::ng-deep .sc-ion-modal-md-h {
--width: 90%;
--height: 70%;
  }
Capo answered 20/12, 2020 at 16:2 Comment(0)
M
1

in TS file:

  async MyModal() {
    const modal = await this.modalController.create({
      component: MyModalPage,
      backdropDismiss: true,
      cssClass: 'my-modal',
    });
    return await modal.present();
  }

in SCSS file:

.my-modal {
  --width: 70%;
  --height: 35%;
}
Mycetozoan answered 29/12, 2020 at 12:53 Comment(0)
G
1

Assign a class to modal (ionic-4 & ionic-5)

this.modalCtrl
  .create({
    component: ReportEventComponent,
    cssClass: 'add-contact-modal'
  })
  .then(modalEl => {
    modalEl.present();
    return modalEl.onDidDismiss();
});

put your css code into global.css file

ion-modal.add-contact-modal {
  --height: 85%;
  --width: 90%;
}
Gossamer answered 30/5, 2021 at 8:9 Comment(0)
M
1

I'm on Ionic 6 and it worked here. Add in global.scss:

.premio-modal{
  // background-color: red;
  .modal-wrapper{
    background: rgba(0, 0, 0, 0.5) !important;
    /* padding: 20% 10% !important; */
    width: 70%;
    height: 75%;
    border-radius: 5px;
  }
}

In component:

async showModal(){
        const modal = await this.modalController.create({
          component: YourComponent,
          cssClass: 'premio-modal',
          backdropDismiss: true,
          
        });
        modal.onDidDismiss().then(
          (m: any) => {
          }
        );
        return await modal.present();
      }
Manuscript answered 22/12, 2021 at 22:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.