Set bootstrap modal body height by percentage

后端 未结 5 590
傲寒
傲寒 2021-01-31 03:09

I am trying to make a modal with a body that will scroll when the content becomes too large. However, I want the modal to be responsive to the screen size. When I set the max-he

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-31 03:16

    Instead of using a %, the units vh set it to a percent of the viewport (browser window) size.

    I was able to set a modal with an image and text beneath to be responsive to the browser window size using vh.

    If you just want the content to scroll, you could leave out the part that limits the size of the modal body.

    /*When the modal fills the screen it has an even 2.5% on top and bottom*/
    /*Centers the modal*/
    .modal-dialog {
      margin: 2.5vh auto;
    }
    
    /*Sets the maximum height of the entire modal to 95% of the screen height*/
    .modal-content {
      max-height: 95vh;
      overflow: scroll;
    }
    
    /*Sets the maximum height of the modal body to 90% of the screen height*/
    .modal-body {
      max-height: 90vh;
    }
    /*Sets the maximum height of the modal image to 69% of the screen height*/
    .modal-body img {
      max-height: 69vh;
    }
    

提交回复
热议问题