Ionic 2 Modal make 50% of the width

后端 未结 2 990
萌比男神i
萌比男神i 2020-12-13 22:28

I have a page in my ionic application that on button click opens a Modal Page. Currently, I have override the variable.scss to the code below to make the model cover the 100

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 23:10

    You can not change a particular modal height or width. Now, I will describe an solution which I use to resize my modal.

    1. Ensured that all modal height and width should be 100%. As ionic resize modal for large screen devices. That's why I added below code in app.scss.

    modal-wrapper {
      position: absolute;
      width: 100%;
      height: 100%;
    }
    
    @media not all and (min-height: 600px) and (min-width: 768px) {
      ion-modal ion-backdrop {
        visibility: hidden;
      }
    }
    
    @media only screen and (min-height: 0px) and (min-width: 0px) {
      .modal-wrapper {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
      }
    }

    1. Now In ion-content we make two div and the background of ion-content should be transparent (see main-view css class). Now, One div is used for background of the modal, this will use as backdrop (see overlay css class). Another div should be used for the content, we will resize this div (see modal-content css class).In example I resize the height to 50%. Sample html ans css code is given below,

    page-about {
      .main-view{
        background: transparent;
      }
      .overlay {
        position: fixed;
        top: 0;
        width: 100%;
        height: 100%;
        z-index: 1;
        opacity: .5;
        background-color: #333;
      }
      .modal_content {
        position: absolute;
        top: calc(50% - (50%/2));
        left: 0;
        right: 0;
        width: 100%;
        height: 50%;
        padding: 10px;
        z-index: 100;
        margin: 0 auto;
        padding: 10px;
        color: #333;
        background: #e8e8e8;
        background: -moz-linear-gradient(top, #fff 0%, #e8e8e8 100%);
        background: -webkit-linear-gradient(top, #fff 0%, #e8e8e8 100%);
        background: linear-gradient(to bottom, #fff 0%, #e8e8e8 100%);
        border-radius: 5px;
        box-shadow: 0 2px 3px rgba(51, 51, 51, .35);
        box-sizing: border-box;
        -moz-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        overflow: hidden;
      }
    }
    
      

    Here is a screen shot of the modal,

    If you want modal content should scroll then replace

提交回复
热议问题